题目
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5+10;
int price[33];
int f[N];
int main()
{
int n, x;
cin >> n >> x;
int total = 0;
for(int i = 1; i <= n; i++) cin >> price[i], total += price[i];
int v = total - x;
for(int i = 1; i <= n; i++)
{
for(int j = v; j >= price[i]; j--)
{
f[j] = max(f[j], f[j-price[i]] + price[i]);
}
}
cout << total - f[v];
return 0;
}