Pagini recente » Cod sursa (job #1476831) | Cod sursa (job #2965129) | Cod sursa (job #2063143) | Cod sursa (job #2068825) | Cod sursa (job #30816)
Cod sursa(job #30816)
#include<stdio.h>
int n,w,wmax,e,i,j,g;
long a[10000],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);
for(j=wmax;j>=0;j--)
if(a[j+e]==0||a[j+e]>a[j]+g) {a[j+e]=a[j]+g;
if(j+e>wmax) wmax=j+e;}}
s=-1;
for(i=w;i<=wmax;i++)
if(a[i]&&(s==-1||a[i]<s)) s=a[i];
printf("%ld",s);
fclose(stdout);
return 0;}