/ * * Naked 01 knapsack problem * Not nonsense directly on the code * / #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define MAXN 12881 int dp[MAXN]; int zero_one_package(int max_v, int n) { int w, val; memset(dp, 0, sizeof(dp)); for(int i = 0; i < n; i ++) { scanf("%d %d", &w, &val); for(int v = max_v; v >= w; v --) { dp[v] = max(dp[v], dp[v-w]+val); } } return dp[max_v]; } int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("test.in", "r", stdin); #endif int v, n; while( ~scanf("%d %d", &n, &v) ) { printf("%d\n", zero_one_package(v, n)); } return 0; }