Pagini recente » Cod sursa (job #509371) | Cod sursa (job #3031652) | Cod sursa (job #2325350) | Cod sursa (job #1695651) | Cod sursa (job #1686215)
#include <iostream>
#include <fstream>
using namespace std;
int G, n;
int main() {
ifstream input("rucsac.in");
input >> n >> G;
int W[G + 1];
int sub[G + 1];
for (int i = 0; i <= G; i++) {
W[i] = 0;
}
for (int i = 0; i < n; i++) {
for (int i = 0; i <= G; i++) {
sub[i] = W[i];
}
int cw, cp;
input >> cw >> cp;
for (int y = 0; y <= G; y++) {
int ww = y + cw;
int pp = W[y] + cp;
if (pp > W[ww]) sub[ww] = pp;
}
for (int i = 0; i <= G; i++) {
W[i] = sub[i];
}
}
int max = 0;
for (int i = 1; i <= G; i++) {
if(W[i] > max) max = W[i];
}
ofstream output("rucsac.out");
output << max << '\n';
output.close();
return 0;
}