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

using namespace std;
typedef long long ll;

int main(){
    int n; cin >> n;

    ll ans = 0;

    vector<ll> v(n);
    for(int i = 0; i < n; ++i){
        ll a, b;
        cin >> a >> b;

        ans += a;
        v[i] = b - a;
    }
    sort(v.begin(), v.end());
    for(int i = n/2; i < n; ++i)
        ans += v[i];

    cout << ans << endl;

	return 0;
}
Copy
Two Teams Mohamedmaher
GNU G++17
199 ms
2.6 MB
Accepted