Result: Accepted
Time: 5ms
Memory: 1716kB
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct ever{
int a,b;
double c;
}arr[15];
int cmp(const ever & x,const ever &y){
if(x.c==y.c) return x.b<y.b;
return x.c<y.c;
}
int main()
{
int t,n,m;
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&arr[i].a);
for(int i=1;i<=n;i++) scanf("%d",&arr[i].b),arr[i].c=arr[i].b/1.0/arr[i].a;
sort(arr+1,arr+1+n,cmp);int tt=n;double ans=0;
// for(int i=1;i<=n;i++){
// printf("%d %d %.2f\n",arr[i].a,arr[i].b,arr[i].c);
// }
while(m>0&&tt>=1){
if(arr[tt].a<=m) ans+=arr[tt].b,m-=arr[tt].a,tt--;
else ans+=arr[tt].c*m,m=0;
}
printf("%.2f\n",ans+1e-7);
}
}