Click Here to go back to the homepage.

Falling Apart Solution:


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

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n_pieces;
    cin >> n_pieces;
    int pieces[n_pieces];
    for(auto &i: pieces){
        cin >> i;
    }
    sort(pieces, pieces + n_pieces, greater<int>());
    int a = 0,b = 0;
    for(int i = 0; i < n_pieces; i++){
        if (i & 1){
            b += pieces[i];
        } else {
            a += pieces[i];
        }
    }
    cout << a << " " << b;
    return 0;
}