Pagini recente » Cod sursa (job #1085011) | Cod sursa (job #1764924) | Cod sursa (job #735180) | Cod sursa (job #3129144) | Cod sursa (job #2542287)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
struct rucsac
{
int w, p;
};
rucsac R[5001];
int O[10001];
int main()
{
int n, G;
f >> n >> G;
for(int i = 1; i <= n; i++)
f >> R[i].w >> R[i].p;
int rez=0;
for(int i = 1; i <= n; i++)
{
for(int j = G - R[i].w; j >= 0; j--)
{
O[j + R[i].w] = max(O[j + R[i].w], O[j] + R[i].p);
rez = max(rez, O[j + R[i].w]);
// g<<rez<<endl;
}
}
g << rez;
}