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: 9ms
Memory: 3280kB
Author: 2018212212246
In contest: 1273

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
const int MAXN = 1e5 + 6;
const double ps = 1e-7;
struct node 
{
	int w, v;
	double p;
}S[MAXN];
bool cmp(node a, node b) 
{
	return a.p > b.p;
}
int main() 
{
	int t;
	cin >> t;
	while (t--) 
	{
		int n, m;
		double sum = 0.0;
		cin >> n >> m;
		for (int i = 0; i < n; i++)
			cin >> S[i].w;
		for (int i = 0; i < n; i++)
			cin >> S[i].v;
		for (int i = 0; i < n; i++)
			S[i].p = 1.0 * S[i].v / S[i].w;
		sort(S, S + n, cmp);
		for (int i = 0; i < n; i++) 
		{
			//printf("S.p:%lf %d\n",S[i].p,S[i].w);
			if (m - S[i].w <= 0)
			{
				sum += S[i].p * m;
				break;
			}
			else
			{
				sum += S[i].v;
				m -= S[i].w;
			}
			//printf("%d\n", m);
		}
		printf("%.2lf\n",sum+ps);
	}
	return 0;
}