Cod sursa(job #1668521)
| Utilizator | Data | 29 martie 2016 20:46:12 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int n,i,j,gr,mx,x,y,b[10001];
int main()
{
f >> n >> gr;
f >> x >> y;
b[x] = y;
for(i = 2; i <= n; ++i)
{
f >> x >> y;
for(j = gr - x; j >= 0; --j)
if(b[j] > 0)
if(b[j + x] == 0 || b[j + x] < b[j] + y)
b[j + x] = b[j] + y;
if(b[x] == 0 || b[x] < y)
b[x] = y;
}
mx = 0;
for(i = 1; i <= gr; ++i)
if(b[i] > mx)
mx = b[i];
g << mx << '\n';
return 0;
}
