Pagini recente » Cod sursa (job #148216) | Cod sursa (job #2586265) | Cod sursa (job #1754815) | Cod sursa (job #2195680) | Cod sursa (job #2932394)
#include <fstream>
using namespace std;
int greu[10005], efort[10005];
int main()
{
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int n, g, gr, ef, i, j, maxx=0;
in>>n>>g;
greu[0]=1;
for (i=1;i<=n;i++) {
in>>gr>>ef;
for (j=g;j>=0;j--) {
if (greu[j]==1) {
greu[j+gr]=1;
if (efort[j+gr]<ef+efort[j]) {
efort[j+gr]=ef+efort[j];
}
if (j+gr<=g) {
maxx=max(maxx, efort[j+gr]);
}
}
}
}
out<<maxx;
return 0;
}