Pagini recente » Cod sursa (job #2759624) | Cod sursa (job #1353528) | Cod sursa (job #829468) | Cod sursa (job #3041277) | Cod sursa (job #92263)
Cod sursa(job #92263)
#include <stdio.h>
int p[15001];
int main ()
{
int g, w, e[1001],c[1001],i,j,t=0,maxe=0,min=10000000;
p[0]=1;
FILE *in=fopen("energii.in","r"), *out=fopen("energii.out","w");
fscanf(in,"%d%d",&g,&w);
for(i=0;i<g;i++)
{
fscanf(in,"%d%d",&e[i],&c[i]);
t+=e[i];
if(e[i]>maxe) maxe=e[i];
}
if(t<w)
{
fprintf(out,"-1\n");
return 0;
}
for(i=0;i<g;i++)
for(j=w+e[i];j>=0;j--)
if(p[j])
p[j+e[i]]=p[j]+c[i];
for(i=w;i<w+maxe;i++)
if(p[i]&&p[i]<min) min=p[i];
fprintf(out,"%d\n",min-1);
return 0;
}