Skip to content

Instantly share code, notes, and snippets.

@igaryhe
Created May 12, 2015 15:48
Show Gist options
  • Save igaryhe/855b6a5134ca5bbabde1 to your computer and use it in GitHub Desktop.
Save igaryhe/855b6a5134ca5bbabde1 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
#define MAX 2000
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i != t; ++i) {
int n, k;
vector<int> v;
cin >> n >> k;
for (int j = 0; j != n; ++j) {
int a;
cin >> a;
v.push_back(a);
}
int dp[MAX + 1] = {0};
for (int i = 0; i < n; ++i)
for (int j = 0; j <= k; ++j)
if (j >= v[i]) dp[j] = max(dp[j], dp[j - v[i]] + v[i]);
cout << dp[k] << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment