Cod sursa(job #1612053)
| Utilizator | Data | 24 februarie 2016 18:00:51 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
#include <vector>
using namespace std;
ifstream is("rucsac.in");
ofstream os("rucsac.out");
int n, m, answ;
int g, p, r[10001];
int main()
{
is >> n >> m;
r[0] = 1;
for ( int i = 1; i <= n; ++i )
{
is >> g >> p;
for ( int j = min(answ, m - g); j >= 0; --j )
if ( r[j] )
{
r[j + g] = max(r[j + g], r[j] + p);
answ = max(answ, r[j + g]);
}
}
os << answ - 1;
is.close();
os.close();
return 0;
}
