Pagini recente » Cod sursa (job #4827) | Cod sursa (job #2671396) | Cod sursa (job #3273356) | Cod sursa (job #2965147) | Cod sursa (job #30819)
Cod sursa(job #30819)
#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<10000) wmax=j+e;}}
s=-1;
/*for(i=w;i<=wmax;i++)
if(a[i]&&(a[i]<s||s==-1)) s=a[i];*/
if(a[w]) s=a[w];
printf("%ld",s);
fclose(stdout);
return 0;}