Source Code
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define int ll

const long double PI = atan(1) * 4.0;

int32_t main(){
    FAST
    int n; cin >> n;
    int sum = 0;
    priority_queue<int> pq;
    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        sum += a;
        pq.push(b - a);
    }
    int cnt = n/2;
    while(cnt--){
        sum += pq.top();
        pq.pop();
    }
    cout << sum;
    return 0;
}
Copy
Two Teams Basilhijaz
GNU G++17
64 ms
3.2 MB
Accepted