Pagini recente » Cod sursa (job #2211819) | Cod sursa (job #511613) | Cod sursa (job #30800) | Cod sursa (job #3244644) | Cod sursa (job #30836)
Cod sursa(job #30836)
#include<stdio.h>
int n,w,wmax,e,i,j,g;
long a[50000],s;
int main()
{freopen("energii.in","r",stdin);
freopen("energii.out","w",stdout);
scanf("%d %d",&n,&w);
for(i=1;i<=n;i++)
{scanf("%d %d",&e,&g);
if(w>wmax) j=wmax;
else j=w;
for(;j>=0;j--)
if((a[j]||j==0)&&(a[j+e]==0||a[j+e]>a[j]+g)) {a[j+e]=a[j]+g;
if(j+e>wmax&&wmax<50000) wmax=j+e;}}
if(wmax>=w) s=2147483647;
else s=-1;
for(i=w;i<=wmax;i++)
if(a[i]&&a[i]<s) s=a[i];
printf("%ld",s);
fclose(stdout);
return 0;}