Pagini recente » Cod sursa (job #365170) | Cod sursa (job #2413135) | Cod sursa (job #16734) | Cod sursa (job #694694) | Cod sursa (job #1804220)
#include <fstream>
#include <algorithm>
using namespace std;
const int G=10005;
int n,g,w,p,maxx,d[G];
int main()
{
ifstream in("rucsac.in");
ofstream out("rucsac.out");
in>>n>>g;
for(int k=1;k<=n;k++){
in>>w>>p;
if(w>g or p==0) continue;
for(int j=g-w;j>=0;j--){
if(d[j+w]<d[j]+p){
d[j+w]=d[j]+p;
}
}
}
for(int i=g;i>=0;i--){
if(d[i]>maxx){
maxx=d[i];
}
}
out<<maxx<<"\n";
return 0;
}