Result: Accepted
Time: 6ms
Memory: 1716kB
#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;
}