https://www.luogu.com.cn/problem/P1049
#include<bits/stdc++.h>
#define lc p<<1
#define rc p<<1|1
#define INF 2e9
using namespace std;
#define endl '\n'
using ll = long long;
using pii = pair<ll, ll>;
const double PI = acos(-1);
const int N=110;
int f[20010];
int v[35];
void solve(){
int V;cin>>V;
int n;cin>>n;
for(int i=1;i<=n;i++)
cin>>v[i];
for(int i=1;i<=n;i++)
for(int j=V;j>=1;j--){
if(v[i]<=j){
f[j]=max(f[j],f[j-v[i]]+v[i]);
}
}
cout<<V-f[V];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
}
浙公网安备 33010602011771号