#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...