Cod sursa(job #218900)

Utilizator alex3el_n2oAlex Vladescu alex3el_n2o Data 3 noiembrie 2008 21:44:43
Problema Energii Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <stdio.h>
int g,w,e[2000],c[2000];
long rez,i,t=0,S,s[10005],max,j;
int main()
{
freopen("energii.in","r",stdin);
freopen("energii.out","w",stdout);
scanf("%d%d",&g,&w);
for (i=1;i<=g;i++)
	scanf("%d %d",&e[i],&c[i]);
s[0]=0;
max=0;
for (i=1;i<=g;i++)
	{
	for (j=max;j>=0;j--)
		if (s[j+e[i]]<s[j]+c[i])
			{
			s[j+e[i]]=s[j]+c[i];
			if (j+e[i]>max) max=j+e[i];
			}
	t+=e[i];
	}
rez=2000000000;
for (i=w;i<=max;i++)
	if (rez>s[i])  rez=s[i];
if (rez==2000000000) printf("-1\n");
else printf("%ld\n",rez);
return 0;
}