Pagini recente » Cod sursa (job #1077325) | Cod sursa (job #104373) | Cod sursa (job #3227496) | Cod sursa (job #123506) | Cod sursa (job #3184542)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string.h>
#define N_MAX 5000
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
const int GMAX = 1e4 + 2;
int dp[GMAX], n, w, p, g, rez;
int main (){
in >> n >> g;
for (int i=1; i<=n; ++i){
in >> w >> p;
dp[0] = 0;
for (int j=g; j >= 0; --j){
if (j - w >= 0)
dp[j] = max(dp[j], dp[j-w] + p);
else
dp[j] = dp[j];
if (dp[j] > rez)
rez = dp[j];
}
}
out << rez;
return 0;
}