Cod sursa(job #577088)

Utilizator andrici_cezarAndrici Cezar andrici_cezar Data 9 aprilie 2011 18:43:59
Problema Energii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<stdio.h>

struct pct{long x; long y;} a[1002], aux;
long n, w, i, s, e, j;

int main()
{
	freopen("energii.in","r",stdin);
	freopen("energii.out","w",stdout);
	
		scanf("%ld", &n);
		scanf("%ld", &w);
		
		for (i = 1; i <= n; i ++)
			scanf("%ld %ld", &a[i].x, &a[i].y);
		
		for (i = 1; i < n; i ++)
			for (j = i + 1; j <= n; j ++)
				if ((double)a[i].x / a[i].y < (double)a[j].x / a[j].y)
					aux = a[i], a[i] = a[j], a[j] = aux;
		
		s += a[1].x;
		e += a[1].y;
		i = 2;
		while (s < w)
		{
			s += a[i].x;
			e += a[i].y;
			i ++;
		}
		
		printf("%ld\n", e);
	
	return 0;
}