Result: Accepted
Time: 5ms
Memory: 1096kB
#include<cstdio>
#include<algorithm>
using namespace std;
struct my
{
double w,v;
double ave;
};
bool comp(my a,my b)
{
return a.ave>b.ave;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;double m;my sz[10];
scanf("%d%lf",&n,&m);
for(int i=1;i<=n;i++)
scanf("%lf",&sz[i].w);
for(int i=1;i<=n;i++)
scanf("%lf",&sz[i].v);
for(int i=1;i<=n;i++)
sz[i].ave=sz[i].v/sz[i].w;
sort(sz+1,sz+n+1,comp);
double ans=0;
for(int i=1;i<=n;i++)
{
if(m-sz[i].w>0)
{
ans+=sz[i].v;
m-=sz[i].w;
}
else
{
ans+=sz[i].ave*m;
break;
}
}
printf("%.2f\n",ans+1e-7);
}
return 0;
}