Pagini recente » Cod sursa (job #1722254) | Cod sursa (job #2375207) | Cod sursa (job #1271349) | Cod sursa (job #458882) | Cod sursa (job #2930575)
#include <fstream>
#include <cstring>
using namespace std;
int main() {
int n, gmax;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
fin >> n >> gmax;
int *v = new int[gmax + 1];
memset(v, 0, (gmax + 1) * sizeof(int));
for (int i = 1; i <= n; i++) {
int g, p;
fin >> g >> p;
for (int j = gmax; j >= g; j--) {
v[j] = max(v[j], p + v[j - g]);
}
}
fout << v[gmax] << '\n';
delete[] v;
return 0;
}