Pagini recente » Cod sursa (job #795758) | Cod sursa (job #2065378) | Cod sursa (job #1244722) | Cod sursa (job #849208) | Cod sursa (job #490256)
Cod sursa(job #490256)
#include <fstream>
using namespace std;
const char InFile[]="energii.in";
const char OutFile[]="energii.out";
const int MaxN=5005;
const int MAX=1<<30;
ifstream fin(InFile);
ofstream fout(OutFile);
int W,CGi,EGi,G,sol,cost[MaxN];
int main()
{
for(register int i=0;i<MaxN;++i)
{
cost[i]=MAX;
}
fin>>G>>W;
cost[0]=1;
for(register int i=0;i<G;++i)
{
fin>>EGi>>CGi;
for(register int j=MaxN-1;j>=0;--j)
{
if(cost[j]!=MAX)
{
int pos=j+EGi;
if(pos>W)
{
pos=W;
}
cost[pos]=min(cost[pos],cost[j]+CGi);
}
}
}
fin.close();
if(cost[W]==MAX)
{
cost[W]=0;
}
fout<<cost[W]-1;
fout.close();
return 0;
}