Pagini recente » Cod sursa (job #1388061) | Cod sursa (job #2661744) | Rating Harangus Daiana (HDaiana) | Cod sursa (job #1313517) | Cod sursa (job #2891712)
#include <bits/stdc++.h>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
const int GMAX=10001;
const int oo=1000000000;
int n,G,w,p,profit[GMAX],profiMaxim;
int main()
{
f>>n>>G;
for(int gr=1;gr<=G;gr++)
profit[gr]=-oo;
for(int i=1;i<=n;i++)
{
f>>w>>p;
for(int newG=G,oldG=G-w;oldG>=0;newG--,oldG--)
profit[newG]=max(profit[newG],profit[oldG]+p);
}
for(int gr=1;gr<=G;gr++)
profiMaxim=max(profiMaxim,profit[gr]);
return 0;
}