#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
using namespace std;
struct Mooncake{
float demand;
float price;
float xjb;
};
Mooncake mooncake[1005];
bool cmp1(Mooncake a,Mooncake b)
{
return a.xjb>b.xjb;
}
int main()
{
cout<<fixed<<setprecision(2);
int n;
cin>>n;
float totaldemand;
cin>>totaldemand;
for(int i=0;i<n;i++)
cin>>mooncake[i].demand;
for(int i=0;i<n;i++)
cin>>mooncake[i].price;
for(int i=0;i<n;i++)
mooncake[i].xjb=mooncake[i].price/mooncake[i].demand;
float sum=0,earn=0;
sort(mooncake,mooncake+n,cmp1);
int now=0;
while(sum<totaldemand)
{
if(sum+mooncake[now].demand<=totaldemand)
{
sum+=mooncake[now].demand;
earn+=mooncake[now].price;
now++;
if(now>=n)
break;
}
else
{
float temp=totaldemand-sum;
sum+=totaldemand-sum;
earn+=mooncake[now].price*temp/mooncake[now].demand;
now++;
if(now>=n)
break;
}
}
cout<<earn;
return 0;
}
没想到有一天自己也会有读题的亏 -------- 保留两位小数
1070 Mooncake (25 分)
最新推荐文章于 2024-07-13 19:27:27 发布