Pagini recente » Cod sursa (job #1427093) | Cod sursa (job #1332297) | Cod sursa (job #3282767) | Cod sursa (job #1011418) | Cod sursa (job #2711736)
#include <bits/stdc++.h>
#define pp pair< int, int >
#define g first
#define p second
using namespace std;
const int mxn = 5000 + 10;
const int mxg = 10 * 1000 + 10;
pp obiecte[ mxn ];
int pret[ mxn ];
int solutie = 0;
int main(){
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
int n, g;
cin>> n >> g;
for(int i = 0, x, y; i < n; i++){
cin>> obiecte[ i ].g >> obiecte[ i ].p;
}
for(int i = 0; i < n; i++){
int x = obiecte[ i ].g;
int y = obiecte[ i ].p;
for(int j = g - x, nx, ny; j >= 0; j--){
nx = j + x;
ny = pret[ j ] + y;
if(pret[ nx ] < ny){
pret[ nx ] = ny;
solutie = max(solutie, ny);
}
}
}
cout<< solutie;
return 0;
}