提交时间:2023-12-04 13:54:26

运行 ID: 113917

include<bits/stdc++.h> using namespace std; int a[35] , f[20005]; int main() { int n , m; cin >> m >> n; for(int i = 1;i <= n;i++) cin >> a[i]; for(int i = 1;i <= n;i++) { for(int j = m;j >= a[i];j--) f[j] = max(f[j] , a[i] + f[j - a[i]]); } cout << m - f[m] <<endl; return 0; }