Result: Accepted
Time: 10ms
Memory: 1716kB
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
struct zongzi{
double a;
double b;
double c;
}s[20];
bool CMP(const zongzi &a,const zongzi &b){
return a.c>b.c;
}
int main(){
int t;
cin>>t;
while(t--){
int n;
double m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>s[i].a;
}
for(int i=1;i<=n;i++){
cin>>s[i].b;
s[i].c=s[i].b/s[i].a;
}
sort(s+1,s+1+n,CMP);
int cnt=1;
double sum=0;
while(m>s[cnt].a&&cnt<=n){
sum+=s[cnt].b;
m-=s[cnt].a;
cnt++;
}
if(cnt<=n) sum+=m*s[cnt].c;
printf("%.2lf\n",sum+1e-7);
}
}