Cod sursa(job #30819)

Utilizator razvi9Jurca Razvan razvi9 Data 15 martie 2007 10:21:46
Problema Energii Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 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<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;}