Pagini recente » Cod sursa (job #655556) | Cod sursa (job #682033) | Cod sursa (job #2961077) | Cod sursa (job #1603208) | Cod sursa (job #1601962)
#include <iostream>
#include <fstream>
#include <utility>
#include <vector>
using namespace std;
vector<pair<int, int> > Ob;
int nrO, G, a, b, pMax;
int main()
{
freopen("rucsac.in", "rt", stdin);
freopen("rucsac.out", "wt", stdout);
scanf("%d%d", &nrO, &G);
Ob.push_back(make_pair(0, 0));
for(int i=1; i<=nrO; ++i){
scanf("%d%d", &a, &b);
Ob.push_back(make_pair(a, b));
}
vector<int>D(G+1);
for(int o=1; o<=nrO; ++o)
for( int g=G; g>=0; --g)
if(Ob[o].first <= g)
D[g] = max(D[g], (D[g - Ob[o].first] + Ob[o].second) );
for(int i=0; i<=G; ++i)
pMax = max(pMax, D[i]);
cout<<pMax<<'\n';
}