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: 1716kB
Author: 2018212212030
In contest: 1273

#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <list>
	using namespace std;
#define ll long long                                               
#define inf 0x3f3f3f3f
int i, j, k;
int m, n, p;
double a[100], b[100],c[100];
int main() {
	int t;
	scanf("%d", &t);
	double tt;
	while (t--) {
		scanf("%d %lf", &n, &tt);
		for (i = 0; i < n; i++) {
			scanf("%lf", &a[i]);
		}
		for (i = 0; i < n; i++) {
			scanf("%lf", &b[i]);
		}
		for (i = 0; i < n; i++) {
			c[i] = b[i] / a[i];
		}
		for (j = 0; j < n; j++){
			for (k = j + 1; k < n; k++)
				if (c[k] > c[j]){
					double h = c[j];
					c[j] = c[k];
					c[k] = h;
					h = a[j];
					a[j] = a[k];
					a[k] = h;
					h = b[j];
					b[j] = b[k];
					b[k] = h;
				}
		}
		double res = 0.0;
		for (i = 0; i < n; i++) {
			if (tt >= a[i]) {
				tt = tt - a[i];
				res = res + b[i];
			}
			else {
				res = res + tt * c[i];
				break;
			}
		}
		printf("%.2f\n", (res+(1e-7)));
	}
	return 0;
}