Pagini recente » Borderou de evaluare (job #1717343) | Cod sursa (job #329253) | Cod sursa (job #1123873) | Cod sursa (job #1706889) | Cod sursa (job #1663961)
#include<fstream>
using namespace std;
int n, G, i, xg, xp, x[10003], gmax, sol;
ifstream in("ruksak.in");
ofstream out("ruksak.out");
int main(){
in>>n>>G;
for(;n--;){
in>>xg>>xp;
for(i=gmax; i>=0; i--){
if(i+xg<=G && xp+x[i]>x[i+xg]){
x[i+xg]=xp+x[i];
if(i+xg>gmax && i+xg<G)
gmax=i+xg;
if(x[i+xg]>sol)
sol=x[i+xg];
}
}
}
out<<sol;
return 0;
}