挺简单的,注意下供不应求的情况即可
#include<stdio.h>
#include<stdlib.h>
struct zlh{
double c;
double d;
double e;
};
int main(){
int a,j=0;
struct zlh yb[1001]={};
double b,k=0,s=0,r=0,m=0;
scanf("%d%lf",&a,&b);
for(int i=1;i<=a;i++){
scanf("%lf",&yb[i].c);
r+=yb[i].c;
}
for(int i=1;i<=a;i++){
scanf("%lf",&yb[i].d);
m+=yb[i].d;
yb[i].e=yb[i].d/yb[i].c;
}
for(int i=1;i<a;i++)
for(int t=i+1;t<=a;t++)
if(yb[i].e<yb[t].e){
struct zlh p;
p=yb[i];
yb[i]=yb[t];
yb[t]=p;
}
if(r<b){
printf("%.2lf\n",m);
exit(0);
}
while(k<b){
j++;
s+=yb[j].d;
k+=yb[j].c;
}
s-=yb[j].d;
s+=(b-k+yb[j].c)*yb[j].e;
printf("%.2lf\n",s);
}