#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
using namespace std;
class yuebin_kinds
{
public:
yuebin_kinds() = default;
yuebin_kinds(const double &rhp, const double &lhp) :weights(rhp), total_price(lhp) {};
double &get_weigths() { return weights; }
double &get_total_price() { return total_price; }
const double get_aver()
{
if (weights == 0)
return 0.0;
else
return (total_price / weights);
}
private:
double weights = 0;
double total_price = 0;
};
int main()
{
unsigned n = 0;
double d = 0;
cin >> n >> d;
vector<yuebin_kinds> yuebing(n);
for (unsigned i = 0; i < n; ++i)
{
double tmp_weights;
cin >> tmp_weights;
yuebing[i].get_weigths() = tmp_weights;
}
for (unsigned i = 0; i < n; ++i)
{
double tmp_total_price;
cin >> tmp_total_price;
yuebing[i].get_total_price() = tmp_total_price;
}
sort(yuebing.begin(), yuebing.end(), [](yuebin_kinds &lhy, yuebin_kinds &rhy) {return lhy.get_aver() > rhy.get_aver(); });
double earn_max_price = 0;
for (auto &r : yuebing)
{
if (r.get_weigths() >= d)
{
earn_max_price = earn_max_price + r.get_aver()*d;
break;
}
else
{
earn_max_price = earn_max_price + r.get_total_price();
d = d - r.get_weigths();
}
}
cout.setf(ios::fixed);
cout << setprecision(2) << earn_max_price;
cout << endl;
system("pause");
return 0;
}
1020
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 传送门 https://pintia.cn/problem-sets/994805260223102976/pro...