Cod sursa(job #30817)
Utilizator | Data | 15 martie 2007 10:17:34 | |
---|---|---|---|
Problema | Energii | Scor | 5 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.41 kb |
#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;}}
if(a[w]) s=a[w];
else s=-1;
printf("%ld",s);
fclose(stdout);
return 0;}