1037 Magic Coupon (25分)

2020-02-17  本文已影响0人  量化啦啦啦
image.png
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

int main() {
    int c, p, ans = 0, m = 0, n = 0;
    cin >> c;
    vector<int> coupon(c);
    for (int i = 0; i < c; i++)
        cin >> coupon[i];
    cin >> p;
    vector<int> values(p);
    for (int i = 0; i < p; i++)
        cin >> values[i];
    sort(coupon.begin(), coupon.end());
    sort(values.begin(), values.end());
    while (m < c && n < p && coupon[m] < 0 && values[n] < 0) {
        ans += coupon[m] * values[n];
        m++;
        n++;
    }
    m = c - 1, n = p - 1;
    while (m >= 0 && n >= 0 && coupon[m] > 0 && values[n] > 0) {
        ans += coupon[m] * values[n];
        m--;
        n--;
    }
    cout << ans;
//    system("pause");
    return 0;
}
上一篇下一篇

猜你喜欢

热点阅读