Pagini recente » Cod sursa (job #2829138) | Cod sursa (job #2027114) | Cod sursa (job #2649888) | preoni | Cod sursa (job #847568)
Cod sursa(job #847568)
#include <fstream>
using namespace std;
const int a=2000000000;
int main()
{
int v[5002], G, W, vmin=a,eg[10002],cg[10002];
int i, j;
ifstream f("energii.in");
ofstream g("energii.out");
f>>G>>W;
for(i=1;i<=G;i++)
f>>eg[i]>>cg[i];
for(int i=1;i<=15002;i++)
v[i]=a;
v[0]=0;
for(i=1;i<=G;i++)
for(j=W;j>=0;j--)
if(v[j]!=a && v[j+eg[i]]>v[j]+cg[i])
v[j+eg[i]]=v[j]+cg[i];
for(i=W;i<15001;i++)
if(v[i]<vmin)
vmin=v[i];
if(vmin!=a)
g<<vmin;
else
g<<"-1";
return 0;
}