#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
struct Mooncake{
double Inventory;
double Prices;
double PerPrice;
};
bool cmp(Mooncake a,Mooncake b)
{
return a.PerPrice>b.PerPrice;
}
Mooncake mooncake[1005];
vector<Mooncake> a;
int main()
{
int n;
double d;
cin>>n>>d;
if(n==0)
printf("0.00");
else{
for(int i=0;i<n;i++)
{
cin>>mooncake[i].Inventory;
}
for(int i=0;i<n;i++)
{
cin>>mooncake[i].Prices;
mooncake[i].PerPrice=mooncake[i].Prices/mooncake[i].Inventory;
a.push_back(mooncake[i]);
}
sort(a.begin(),a.end(),cmp);
d=d-a[0].Inventory;
double count=0;
int i=0;
if(d<0)
{
printf("%.2f",(d+a[0].Inventory)*a[0].PerPrice);
}
else{
while(d>0&&i<=n)
{
count+=a[i].Prices;
d=d-a[i].Inventory;
i++;
}
count+=(d+a[i-1].Inventory)*a[i].PerPrice;
printf("%.2f",count);
}
}
}
1070. Mooncake (25)
最新推荐文章于 2021-01-23 23:26:10 发布