1 条题解

  • 0
    @ 2025-11-28 0:25:09
    #include <bits/stdc++.h>
    #define int long long // 仅在需要大整数时使用,memset 数组为 0x3f 时去掉
    #define INF 0x3f3f3f3f
    #define PII pair<int, int>
    #define ULL unsigned long long
    #define PIII tuple<int, int, int>
    #define all(v) v.begin(), v.end()
    #define debug(a) cout << #a << " = " << a << endl;
    using namespace std;
    constexpr int N = 1 * 1e6 + 10, M = 5 * 1e3 + 10;
    
    
    void solve() {
        int n, k;
        cin >> n >> k;
        auto arr = vector<int>(n);
        for (auto &x : arr) cin >> x;
        sort(all(arr));
        int ans = 1e18 + 10;
        for (int l = n - k * 2, r = n - 1, cnt = 0; cnt < k ; l ++, r --, cnt ++) {
            ans = min(arr[l] + arr[r], ans);
        }
        cout << ans << '\n';
    }
    
    signed main() {
        ios::sync_with_stdio(0); cin.tie(nullptr), cout.tie(nullptr);
        int _ = 1;
        // cin >> _;
        while (_--) {
            solve();
        }
        return 0;
    }
    
    /**
     *    author: Nijika_jia
     *    description: C++17 Algorithm Template for Competitive Programming
     */
    
    
    • 1

    信息

    ID
    5632
    时间
    1000ms
    内存
    256MiB
    难度
    3
    标签
    递交数
    25
    已通过
    4
    上传者