比赛 |
20190521热身赛 |
评测结果 |
AAAAAAAAAAA |
题目名称 |
待售干草 |
最终得分 |
100 |
用户昵称 |
gsj.cpp |
运行时间 |
0.230 s |
代码语言 |
C++ |
内存使用 |
14.04 MiB |
提交时间 |
2019-05-21 19:21:18 |
显示代码纯文本
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
using namespace std;
inline int read()
{
char ch=getchar();int x=0,f=1;
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int maxn=50005;
int T,n,t[maxn],f[maxn];
int main()
{
freopen("hay4sale.in","r",stdin);
freopen("hay4sale.out","w",stdout);
T=read(),n=read();
for(int i=1;i<=n;i++)
{
t[i]=read();
}
for(int i=1;i<=n;i++)
for(int j=T;j>=t[i];j--)
{
f[j]=max(f[j],f[j-t[i]]+t[i]);
if(f[j]==T)
{
cout<<T;
return 0;
}
}
cout<<f[T];
return 0;
}