Pagini recente » Cod sursa (job #2162357) | Cod sursa (job #2084360) | Cod sursa (job #30829) | Cod sursa (job #3041608) | Cod sursa (job #30832)
Cod sursa(job #30832)
#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=2147000000;
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;}