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: 11ms
Memory: 1748kB
Author: 2018212212189
In contest: 1273

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1e3+5;
#define mst(a,b) memset(a,b,sizeof a)
int num[maxn],tot_price[maxn];
struct zongzi{
	double unit_price;
	int weight;
}st[maxn];
bool cmp(zongzi x,zongzi y){
	return x.unit_price > y.unit_price ;
}
double unit_price[maxn];
int main()
{
	int T;
	cin>>T;
	while(T--){
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=n;++i)
		cin>>num[i];
		for(int i=1;i<=n;++i)
		cin>>tot_price[i];
		for(int i=1;i<=n;++i){
			st[i].unit_price = tot_price[i]*1.0/num[i];
			st[i].weight = num[i];
		}
		sort(st+1,st+n+1,cmp);
		double sum=0;
		int flag=0;
		for(int i=1;i<=n;++i){
			for(int j=st[i].weight;j>0;j--){
				sum+=st[i].unit_price;
				m--;
				if(m==0){
					flag=1; break;
				}	
			}
			if(flag) break;
		}
		printf("%.2f\n",sum+1e-7);
	}
}