Pagini recente » Cod sursa (job #2543577) | Cod sursa (job #1087811) | Cod sursa (job #1723716) | Cod sursa (job #2773549) | Cod sursa (job #3139090)
#include <iostream>
#include <fstream>
using namespace std;
int total, n, g, w, p;
int v[10002];
int main(){
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
fin >> n >> g;
for(int i = 0; i < n; i++){
fin >> w >> p;
if(p == 0){
continue;
}
total = min(total + w, g);
for(int j = total; j >= w; j--){
v[j] = max(v[j], v[j-w] + p);
}
}
int wins = 0;
for(int i = 0; i <= g; i++) {
wins = max(wins, v[i]);
}
fout << wins;
fin.close();
fout.close();
return 0;
}