#include <cstdio>
#include <algorithm>
using namespace std;
struct moonCake{
double inventory;
double totalPrice;
double unitPrice;
}cake[1010];
bool cmp(moonCake a, moonCake b){
return a.unitPrice > b.unitPrice;
}
int main(){
int n;
double money = 0, d;
scanf("%d %lf", &n, &d);
for(int i = 0; i < n; i++){
scanf("%lf", &cake[i].inventory);
}
for(int i = 0; i < n; i++){
scanf("%lf", &cake[i].totalPrice);
cake[i].unitPrice = cake[i].totalPrice / cake[i].inventory;
}
sort(cake, cake + n, cmp);
for(int i = 0; i < n; i++){
if(d >= cake[i].inventory){
d -= cake[i].inventory;
money += cake[i].totalPrice;
}else{
money += cake[i].unitPrice * d;
break;
}
}
printf("%.2f", money);
return 0;
}
每次把单价最贵的月饼卖完就行了,直到需求满足了