Pagini recente » Cod sursa (job #2033689) | Cod sursa (job #616692) | Cod sursa (job #40989) | Cod sursa (job #2788818) | Cod sursa (job #577088)
Cod sursa(job #577088)
#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;
}