Source Code
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n; cin >> n;
    vector<pair<int,int>> v1(n), v2(n);
    for(int i = 0; i < n; ++i){
        cin >> v1[i].first >> v1[i].second;
        v2[i].first = v1[i].second;
        v2[i].second = v1[i].first;
    }

    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    int a = 0, b = 0;
    for(int i = 1; i <= n; ++i){
        if( 2*i <= n ){
            a += v1[i-1].second;
            b += v2[i-1].second;
        } else {
            a += v1[i-1].first;
            b += v2[i-1].first;
        }
    }

    cout << max(a, b) << endl;

	return 0;
}
Copy
Two Teams Trainee
GNU G++17
4 ms
1.1 MB
Wrong Answer