Result: Accepted
Time: 10ms
Memory: 1716kB
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 200010;
const int inf = 0x3f3f3f3f;
const int mo = 1e9+7;
int t,n,m,l,r,res;
double ans;
struct food{
int w;
int v;
double value;
}a[15];
bool cmp(const food a,const food b){
if(a.value ==b.value )return a.w >=b.w;
else return a.value >b.value ;
}
int main(){
cin>>t;
for(int k=0;k<t;k++){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i].w ;
}
for(int i=0;i<n;i++){
cin>>a[i].v ;
a[i].value =a[i].v *1.0/a[i].w ;
}
sort(a,a+n,cmp);
res=m;
ans=0;
for(int i=0;i<n;i++){
if(res>a[i].w ){
ans+=a[i].v ;
res-=a[i].w ;
}
else{
ans+=a[i].value *res;
break;
}
}
printf("%.2f\n",ans+1e-7);
}
return 0;
}