Pagini recente » Cod sursa (job #3200830) | Cod sursa (job #1979094) | Cod sursa (job #1979089) | Cod sursa (job #1154938) | Cod sursa (job #1549659)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <queue>
#define LL long long
#define pb push_back
#define lm 5001
#define MOD 1000000007
using namespace std;
int w[lm],v[lm];
int opt[10001];
int main()
{
freopen("rucsac.in", "r", stdin);
freopen("rucsac.out", "w", stdout);
int n,g,res=0;
scanf("%d %d",&n,&g);
for(int i=1; i<=n; i++)
{
scanf("%d %d",&w[i],&v[i]);
}
for(int i=1; i<=n; i++)
for(int j= g-w[i] ; j>=0; j--)
{
if(opt[j+w[i]] < opt[j]+v[i])
{
opt[j+w[i]]=opt[j] + v[i];
if(opt[j+w[i]]>res)
res = opt[j+w[i]];
}
}
printf("%d",res);
return 0;
}