bdfz_2024_summer/day13/P1049/P1049.cpp
2024-08-17 11:20:38 +08:00

41 lines
672 B
C++

//AC
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
const int MAX_N=30+5;
const int MAX_V=2e4+5;
int V,n;
int w[MAX_N];
int dp[MAX_V];
int readint();
int main(){
V=readint(),n=readint();
for(int i=1;i<=n;i++){
w[i]=readint();
}
for(int i=1;i<=n;i++){
for(int j=V;j>=w[i];j--){
dp[j]=max(dp[j],dp[j-w[i]]+w[i]);
}
}
cout<<V-dp[V]<<endl;
}
int readint(){
int x=0,w=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-')w=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
}