0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 00:48:47 +00:00
OI-codes/S2OJ/9/9.cpp

31 lines
477 B
C++

#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 20005;
int s, n, a[N], f[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> s >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
for (int j = s; j >= a[i]; j--) {
f[j] = std::max(f[j], f[j - a[i]] + a[i]);
}
}
cout << s - f[s] << endl;
return 0;
}