Mai intai trebuie sa te autentifici.
Cod sursa(job #1603027)
Utilizator | Data | 17 februarie 2016 09:36:57 | |
---|---|---|---|
Problema | Energii | Scor | 40 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.88 kb |
#include <iostream>
#include <fstream>
#include <utility>
#include <vector>
using namespace std;
vector<pair<int, int> > Ob;
int nrGen, eNecesara, energ, cost, pMax, cMax, ok, cmin = 2000000000;
int main()
{
freopen("energii.in", "rt", stdin);
freopen("energii.out", "wt", stdout);
scanf("%d%d", &nrGen, &eNecesara);
Ob.push_back(make_pair(0, 0));
for(int i=1; i<=nrGen; ++i)
{
scanf("%d\n%d", &energ, &cost);
Ob.push_back(make_pair(cost, energ));
cMax += cost;
}
vector<int>D(cMax+5);
for(int o=1; o<=nrGen; ++o)
{
for( cost=cMax; cost>=0 ; --cost)
{
if(Ob[o].first <= cost)
D[cost] = max(D[cost], (D[cost - Ob[o].first] + Ob[o].second) );
if(D[cost] >= eNecesara && cost < cmin)
cmin = cost;
}
}
cout<<cmin<<'\n';
}