Start: Jun, 26, 2019 08:30:00
2019年度暑期短学期第一天
End: Jun, 26, 2019 11:30:00
Time elapsed:
Time remaining:

Problem_ID: H
Result: Accepted
Time: 8ms
Memory: 1092kB
Author: 2018212212245
In contest: 1273

#include <stdio.h>

int main()
{
	int T, n, m, i, j;
	double a[100], b[100], c[100];
	double sum, x, y, z;
	scanf("%d" ,&T);
	while (T--)
	{
		sum = 0;
		scanf("%d %d", &n, &m);
		for (i = 0; i < n; i++)
			scanf("%lf", &a[i]);
		for (i = 0; i < n; i++)
			scanf("%lf", &b[i]);
		for (i = 0; i < n; i++)
			c[i] = b[i] * 1.0 / a[i];
		for (i = 0; i < n; i++)
		{
			for (j = i; j < n; j++)
			{
			if (c[i] < c[j])
			{
				x = a[i];
				a[i] = a[j];
				a[j] = x;
				y = b[i];
				b[i] = b[j];
				b[j] = y;
				z = c[i];
				c[i] = c[j];
				c[j] = z;
			}
			}
		}
		for (i = 0; i < n; i++)
		{
			if (m > a[i])
			{
			    sum += b[i];
				m -= a[i];
			}
			else
			{
				sum += m * c[i];
			    break;
			}
		}
		printf("%.2lf\n", sum + 1e-7);
	}
		return 0;
}