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: 2018212212029
In contest: 1273


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node {
	double we, val, vw;
}a[105];
bool cmp(const node &a, const node &b) {
	return a.vw > b.vw;
}
int main() {
	int t;
	int n, m;
	scanf("%d", &t);
	while (t--) {
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; i++) {
			scanf("%lf", &a[i].we);
		}
		for (int i = 1; i <= n; i++) {
			scanf("%lf", &a[i].val);
			a[i].vw = a[i].val / a[i].we;
		}
		sort(a + 1, a + n+1, cmp);
		double twe = 0, ans = 0;
		for (int i = 1; i <= n; i++) {
			if (twe + a[i].we <= m) twe += a[i].we, ans += a[i].val;
			else {
				ans += (m - twe) / a[i].we*a[i].val;
				break;
			}
		}
		printf("%.2lf\n", ans+1e-7);
	}
}