Result: Accepted
Time: 5ms
Memory: 1096kB
#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);
}
}