优秀的编程知识分享平台

网站首页 > 技术文章 正文

C++ GESP 2025年3月五级真题及解析

nanyue 2025-06-08 23:11:42 技术文章 9 ℃


1


2


题目分析

将 c 数组累计起来,然后将 差值从大到小排序,将前n大的加到 上。

参考程序

#include <bits/stdc++.h>
usingnamespacestd;

typedeflonglong LL;
constint N = 2e5 + 10;

int n;

LL b[N], c[N], d[N];

bool cmp(LL a, LL b){
    return a > b;
}

LL res = 0;

int main() {

    cin >> n;
    for(int i = 1; i <= 2 * n; i++) 
        cin >> b[i];

    for(int i = 1; i <= 2 * n; i++){
        cin >> c[i];
        d[i] = b[i] - c[i];
        res += c[i];
    }

    sort(d + 1, d + 2 * n + 1, cmp);

    for(int i = 1; i <= n; i++)
        res += d[i];

    cout << res;

return0;
}

Tags:

最近发表
标签列表