Pagini recente » Cod sursa (job #1361020) | Cod sursa (job #280842) | Cod sursa (job #1406968) | Cod sursa (job #2538510) | Cod sursa (job #2468204)
#include <fstream>
using namespace std;
ifstream in("energii.in");
ofstream out("energii.out");
const int MAX=10001;
int g,w,eg[MAX],cg[MAX],profit[MAX],k,s;
int main()
{
in>>g;
in>>w;
for(int i=1;i<=g;i++){
in>>eg[i]>>cg[i];
s+=eg[i];
}
if(s<w)
out<<-1;
for(int j=1;j<=w;j++)
profit[j]=10000010;
for(int i=1;i<=g;i++)
for(int j=w-1;j>=0;j--)
if(profit[j]!=10000010){
if(j+eg[i]>=w){
k=w;
}else{
k=j+eg[i];
}
if(profit[j]+cg[i]<profit[k])
profit[k]=profit[j]+cg[i];
}
out<<profit[w];
return 0;
}