Pagini recente » Cod sursa (job #1675792) | Cod sursa (job #1819482) | Cod sursa (job #3183146) | Cod sursa (job #168706) | Cod sursa (job #3220981)
//rucsac
#include <bits/stdc++.h>
using namespace std;
const int nmax = 5005, gmax = 10005;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int N, G, dp[gmax];
typedef struct poza{
int cost, prof;
}student;
student v[nmax];
int main(){
fin>>N>>G;
for(int i=1;i<=N;i++){
fin>>v[i].cost>>v[i].prof;
}
for(int j=1;j<=N;j++){
for(int i=G;i>=1;i--){
if(i - v[j].cost >= 0){
dp[i] = max(dp[i] , dp[i - v[j].cost] + v[j].prof);
}
}
}
fout<<dp[G];
}