Description
Input
Output
Sample Input
2
6
5
The wagon holds 7 volumetric units; three bales are offered for sale with
volumes of 2, 6, and 5 units, respectively.
Sample Output
#include<cstdio> #include<iostream> using namespace std; int v,n; bool f[50001]; int main() { scanf("%d%d",&v,&n); f[0]=1; for (int i=1;i<=n;i++) { int a; scanf("%d",&a); for (int j=v;j>=a;j--) f[j]|=f[j-a]; } for (int i=v;i>=0;i--) if (f[i]) { cout<<i; return 0; } }