Cod sursa(job #2468200)
Utilizator | Data | 5 octombrie 2019 13:24:26 | |
---|---|---|---|
Problema | Energii | Scor | 5 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.7 kb |
#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[k];
return 0;
}