Pagini recente » Rating Rares Ciobanu (rary) | biti3 | Profil Asgari_Armin | Tudor Maxim | Cod sursa (job #2005866)
#include <fstream>
#include <iostream>
using namespace std;
const int G_max = 10001;
const int N_max = 5001;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int DP[G_max], W, P, N, G;
int main() {
in >> N >> G;
for(int i = 1; i < G; i++) {
DP[i] = -2e9;
}
for(int k = 0; k < N; k++) {
in >> W >> P;
for(int h = G; h >= W; h--) {
if(DP[h] < DP[h - W] + P) {
DP[h] = DP[h - W] + P;
}
}
}
int current_max = 0;
for(int k = 0; k <= G; k++) {
if(DP[k] > current_max) {
current_max = DP[k];
}
}
out << current_max;
return 0;
}