L2-003 月饼

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, need;
    cin >> n >> need;
    vector<double> have(n);
    vector<double> price(n);
    for (int i = 0; i < n; i++) {
        cin >> have[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> price[i];
    }
    vector<tuple<double, double, int>> up(n);
    for (int i = 0; i < n; i++) {
        up[i] = {price[i] / have[i], have[i], i};
    }
    sort(up.begin(), up.end(), [&](tuple<double, double, int> x, tuple<double, double, int> y) {
         return get<0>(x) > get<0>(y); 
    });

    double res = 0;
    for (int i = 0; i < up.size(); i++) {
        if (need >= get<1>(up[i])) {
            res += 1.0 * price[get<2>(up[i])];
            need -= get<1>(up[i]);
        } else {
            res += get<0>(up[i]) * 1.0 * need;
            need = 0;
        }
    }

    cout << fixed << setprecision(2) << res;

    return 0;
}
//4.16
//4.8
//
posted @ 2022-03-14 22:43  Xxaj5  阅读(23)  评论(0编辑  收藏  举报