Pagini recente » Monitorul de evaluare | Cod sursa (job #566166) | Cod sursa (job #3299703) | Diferente pentru problema/coduri intre reviziile 11 si 10 | Cod sursa (job #3356239)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("energii.in");
ofstream cout("energii.out");
short int e[10002], c[10002];
vector<int> cost(10000005, 15005);
int main()
{
int g, w, smax, mini=10000005;
cin>>g>>w;
for(int i=1; i<=g; i++)
cin>>e[i]>>c[i];
cost[0]=0;
smax=0;
for(int i=1; i<=g; i++){
for(int j=smax; j>=0; j--)
if(cost[j]!=10000005 && j+e[i]<=15005){
//cout<<" cost[j] initial: "<<cost[j];
if(cost[j]+c[i]<cost[j+e[i]]){
cost[j+e[i]]=cost[j]+c[i];
if(cost[j+e[i]]<mini && j+e[i]>=w)
mini=cost[j+e[i]];
}
//cout<<" cost[j] schimbat: "<<cost[j+e[i]]<<endl;
}
if(smax+e[i]<=15005)
smax+=e[i];
else
smax=15005;
}
/*
cout<<"smax: "<<smax<<endl;
for(int i=0; i<=smax; i++)
cout<<i<<" "<<cost[i]<<endl;
*/
if(mini!=10000005)
cout<<mini;
else
cout<<-1;
return 0;
}