#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;
struct moon
{
double kucun;
double price;
double danprice;
};
bool comp1(moon const& a, moon const& b)//将单价降序排序
{
if (a.danprice > b.danprice)
return true;
else
return false;
}
int main()
{
int num;
cin >> num;
double sumdemand;
cin >> sumdemand;
moon yuebing;
vector<moon> bing(num);
for (int i = 0; i < num; i++)
{
cin >> bing[i].kucun;
}
for (int j = 0; j < num; j++)
{
cin >> bing[j].price;
bing[j].danprice = bing[j].price / bing[j].kucun;
}
sort(bing.begin(), bing.end(), comp1);
//现在已找出单价最高的月饼为bing[0].danprice
double result = 0;
int u = 0;
while (sumdemand >= bing[u].kucun && u <= num)
{
result += bing[u].danprice * bing[u].kucun;
sumdemand -= bing[u].kucun;
u++;
}
if (u > num)
{
cout << fixed << setprecision(2) << result;
}
else
{
result += sumdemand * bing[u].danprice;
cout << fixed << setprecision(2) << result;
}
}
读题很重要,正数没说整数就有可能是小数,其次有可能你要的数量>总库存量