窃取培优1.0

窃取培优1.0

Tag:

Background

The elf passed Gaussian's interrogation and was finally released. In order to avenge, they called in more elves and decided to steal Gaussian's raw material for building the old-age house-"Peiyou New Method". They have just learned that Gauss has ordered a batch of Peiyou online and is being delivered by a courier company. They felt that this was a good opportunity and began to take action.

小精灵通过了高斯的审问,好不容易才被放了出来,为了报仇,他们召集了更多的小精灵,他们决定偷取高斯建造养老房的原材料——《培优新方法》。他们刚刚得知高斯在网上订购了一批培优,正在由快递公司送过来。他们觉得这是一个好机会,便开始了行动。

Description

Every merit book has its own value. In order to steal higher merit books, they handed the problem to you. However, you should know that the transportation company employed by Gauss is very careful. When you steal the total value of Peiyou to reach a certain limit, the elves will be found and arrested. Now, please find out the maximum value that can be stolen from Peiyou without being caught. If there is no maximum value, output \(-1\).

每本培优都有自己的价值,为了偷取价值更高的培优,他们把问题交给了你。但是你要知道,高斯雇佣的运输公司可是十分小心,当你偷到培优的总价值达到(大于即小于等于)一定限制的时候,小精灵们就会被发现而被逮捕,现在,请你在不被抓的情况下,求出能偷取到培优的最大价值。如果没有最大价值,则输出\(-1\)。

Input

The first line, an integer n, indicates how much the merit is, and the elf will be caught.
In the second row, a positive integer \(t\) (\(t < = 100\)) indicates the total number of excellent candidates.
In the next row, there are t integers, which indicate the value of the I-th primary culture.

第一行,一个整数n,表示培优的价值达到多少时,小精灵会被抓
第二行,一个正整数\(t\)(\(t<=100\)),表示培优总数
接下来1行,有\(t\)个整数,表示第\(i\)本培优的价值

Output

An integer that represents the maximum value that can be stolen from Peiyou.
一个整数,分别表示能偷到培优的最大价值。

Sample

Input

100
3
99 1 98

Output

100

Limitation

\(N<=2580000\)

Source

Amorphophallus Orz Group

信息

ID
1000
难度
4
分类
动态规划 | 贪心 点击显示
标签
递交数
42
已通过
5
通过率
12%
上传者

相关

在下列训练计划中:

AOG题库训练计划