1020

#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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 午加餐:石榴晚水果:丰水梨 参考目标: 1份肉2份豆制品3份“新鲜”水果4份谷物/薯5份蔬菜,深绿色叶菜最好6杯水...
    静趣_儿童心理师阅读 183评论 0 0
  • 两个寂寞的灵魂 在一个寂寞的城市 为了逃避寂寞 走在了一起 在你我相遇之前 我们似乎荒废了 望不到尽头的 寂寞的时...
    可爱mice阅读 302评论 0 0
  • 传送门 https://pintia.cn/problem-sets/994805260223102976/pro...
    Rush的博客阅读 2,203评论 0 0
  • 参考书目:《重要的事情说3点》 [日] 八幡纰芦史 三个臭皮匠赛过诸葛亮、三天打鱼两天晒网、事不过三……“3”这个...
    仲夏夜之梦123阅读 221评论 0 0
  • 之前也看过关于“三”的文章,这数字真是太好了,尤其是“重要的事情说三遍”火了很久,三令五申强调命令的重要性,刘备三...
    张德祥阅读 250评论 1 2