WA60pts 求助
查看原帖
WA60pts 求助
804115
yzm0325楼主2024/1/7 21:22

和第一篇题解的思路一样,但是代码都快重合了还是 WA 60pts

#include <bits/stdc++.h>
using namespace std;
int n, m, a[2010], b[2010];
int main() {
    cin >> n >> m;
    for(int i = 1; i < n; i++) cin >> a[i];
    for(int i = 1; i < m; i++) cin >> b[i];
    sort(a + 1, a + n, [](const int &x, const int &y) {return x > y;});
    sort(b + 1, b + n, [](const int &x, const int &y) {return x > y;});
    int za = 1, zb = 1;
    long long ans = 0;
    for(int i = 2; i < n + m; i++) {
        if(a[za] > b[zb]) ans += zb * a[za++];
        else ans += za * b[zb++];
    }
    cout << ans;
    return 0;
}
2024/1/7 21:22
加载中...