1 solutions

  • 0
    @ 2025-11-27 11:59:47

    C++ :

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e5 + 5;
    
    int n;
    
    unordered_map<int, int> f[2]; // 不平衡度 => 最大和
    
    int main() {
    
        cin >> n;
        int a, b, i;
        for (i = 1; i <= n; i++) {
            cin >> a >> b;
    
            f[i & 1] = f[i -  1 & 1];
            for (auto x: f[i - 1 & 1]) {
                f[i & 1][x.first + a - b] = max(f[i & 1][x.first + a - b], x.second + a + b);
            }
    
            f[i & 1][a - b] = max(f[i & 1][a - b], a + b);
        }
        cout << f[i - 1 & 1][0];
    
    }
    
    
    • 1

    Information

    ID
    125
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By