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: 5ms
Memory: 1096kB
Author: 2018212212276
In contest: 1273

#include<cstdio>
#include<algorithm>
using namespace std;

struct my
{
	double w,v;
	double ave;
};
bool comp(my a,my b)
{
	return a.ave>b.ave;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n;double m;my sz[10];
		scanf("%d%lf",&n,&m);
		for(int i=1;i<=n;i++)
			scanf("%lf",&sz[i].w);
		for(int i=1;i<=n;i++)
			scanf("%lf",&sz[i].v);
		for(int i=1;i<=n;i++)
			sz[i].ave=sz[i].v/sz[i].w;
		sort(sz+1,sz+n+1,comp);
		double ans=0;
		for(int i=1;i<=n;i++)
		{
			if(m-sz[i].w>0)
			{
				ans+=sz[i].v;
				m-=sz[i].w;
			}
			else 
			{
				ans+=sz[i].ave*m;
				break;
			}
		}
		printf("%.2f\n",ans+1e-7);
	}
	return 0;
}