xxxxxxxxxx30 1#include2#include3using namespace std;45const int N = 50;6const int M = 3000010;7const int inf = 1e8;89int n, m, sum, re;10int a[N], minn = inf;11int v[M];1213int main()14{15 16 cin >> n >> m;17 for(int i = 1; i <= n; i ++)18 cin >> a[i], sum += a[i];19 re = sum - m;20 for(int i = 1; i <= n; i ++)21 {22 for(int j = re; j >= a[i]; j –)23 {24 v[j] = max(v[j - a[i]] + a[i], v[j]);25 }26 }27 28 cout << sum - v[re] << endl;29 return 0;30}cpp
xxxxxxxxxx30 1#include2#include3using namespace std;45const int N = 50;6const int M = 3000010;7const int inf = 1e8;89int n, m, sum, re;10int a[N], minn = inf;11int v[M];1213int main()14{15 16 cin >> n >> m;17 for(int i = 1; i <= n; i ++)18 cin >> a[i], sum += a[i];19 re = sum - m;20 for(int i = 1; i <= n; i ++)21 {22 for(int j = re; j >= a[i]; j –)23 {24 v[j] = max(v[j - a[i]] + a[i], v[j]);25 }26 }27 28 cout << sum - v[re] << endl;29 return 0;30}cpp