Cod sursa(job #220622)

Utilizator SheepBOYFelix Liviu SheepBOY Data 11 noiembrie 2008 20:21:22
Problema Energii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include<stdio.h>
int v[1000001];
struct G_C{
int e,c;
};
int g,w;
int sum;
G_C energ[1001];
void reorder()
{
	int i,j;
	for(i=0;i<g;i++)
		for(j=sum;j>=0;j--)
			v[j+energ[i].e]=v[j]+energ[i].c;
		for(i=w;;i++)
			if(v[i])
			{
				printf("%d",v[i]);
				break;
			}
		
}
int main()
{
	freopen("energii.in","r",stdin);
	freopen("energii.out","w",stdout);
	scanf("%d%d",&g,&w);	
	int i=0;
	for(i=0;i<g;i++)
	{
		scanf("%d%d",&energ[i].e,&energ[i].c);
		if(sum<energ[i].e)
			sum=energ[i].e;
		if(v[energ[i].e]>energ[i].c)
		v[energ[i].e]=energ[i].c;
	}
	reorder();
	return 0;
}