Cod sursa(job #1777483)
| Utilizator | Data | 12 octombrie 2016 16:03:08 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 65 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, g_max, vec[5005];
void citire()
{
scanf("%d %d\n",&n,&g_max);
int x,y;
for(int i = 0 ; i < n ; ++i)
{
scanf("%d %d\n",&x,&y);
for(int j = g_max ; j >= x ; --j)
{
vec[j] = max(vec[j],vec[j - x] + y);
}
}
printf("%d",vec[g_max]);
}
int main()
{
freopen("rucsac.in","r",stdin);
freopen("rucsac.out","w",stdout);
citire();
return 0;
}
