1 条题解

  • 0
    @ 2025-8-7 8:56:23

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    
    void solve() {
        int n;
        cin >> n;
        n *= 2;
    
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
    
        sort(a.begin(), a.end());
    
        LL ans = 0;
        int l = 0, r = n - 1;
        while (l < r) {
            ans += 1LL * a[l] * a[r];
            l++, r--;
        }
        cout << ans << '\n';
    }
    int main() {
        ios_base ::sync_with_stdio(false);
        cin.tie(0);
        int t = 1;
        while (t--) {
            solve();
        }
        return 0;
    }
    

    信息

    ID
    516
    时间
    1000ms
    内存
    128MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者