You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
449 B
24 lines
449 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 1010;
|
|
int n, m;
|
|
int w[N], v[N];
|
|
int res;
|
|
|
|
void dfs(int u, int r, int s) {
|
|
if (u == n + 1) {
|
|
res = max(res, s);
|
|
return;
|
|
}
|
|
if (v[u] <= r) dfs(u + 1, r - v[u], s + w[u]);
|
|
dfs(u + 1, r, s);
|
|
}
|
|
|
|
int main() {
|
|
cin >> n >> m;
|
|
for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];
|
|
dfs(1, m, 0);
|
|
printf("%d\n", res);
|
|
return 0;
|
|
} |