1 solutions

  • 0
    @ 2024-6-1 16:29:44

    #include <bits/stdc++.h> using namespace std;

    const int N = 10005;

    priority_queue<int, vector, greater > q; int n, ans;

    int main() { cin >> n; int x; for(int i = 1; i <= n; i++) cin >> x, q.push(x);

    while(q.size() >= 2)
    {
        int a = q.top(); q.pop();
        int b = q.top(); q.pop();
        int sum = a + b;
        q.push(sum);
        ans += sum;
    }
    
    cout << ans;
    
    return 0;
    

    }

    • 1

    [NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G

    Information

    ID
    90
    Time
    800ms
    Memory
    125MiB
    Difficulty
    3
    Tags
    # Submissions
    49
    Accepted
    29
    Uploaded By