1020

#include
#include
#include
#include
#include


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 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)