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

#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn = 110;
const double ps = 1e-7;
struct tt{
	int m;
	int p;
	double av;
};
tt a[maxn];
bool cmp(tt a, tt b){
	return a.av > b.av;
}
int main(){
	int T;
	scanf("%d", &T);
	while (T--){
		double pp = 0;
		int n, m;
		scanf("%d%d", &n, &m);
		for (int i = 0; i < n; i++)
			scanf("%d", &a[i].m);
		for (int i = 0; i < n; i++)
			scanf("%d", &a[i].p);
		for (int i = 0; i < n; i++)
			a[i].av = (double)a[i].p / (double)a[i].m;
		sort(a, a + n, cmp);
		for (int i = 0; i < n; i++){
			if (m <= 0)
				break;
			if (m >= a[i].m){
				m -= a[i].m;
				pp += a[i].p;
			}
			else{
				pp += a[i].av*m;
				m = 0;
			}
			//printf("%d %.2lf**\n", m, pp);
		}
		printf("%.2lf\n", pp+ps);
	}
	return 0;
}