Source Code
#include<iostream>
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int mod=1e9+7;
const ll INF=1e18;
const double pi=3.14159265358979323846;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
#define Go ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define Mid ((L+R)/2)

using namespace std;

vector<ll>v;

int main()
{
Go

int n; cin >> n;

ll ans=0;
for(int i=0;i<n;i++){
    ll x,y; cin >> x >> y;
    v.pb(x-y);
    ans+=y;
}
sort(all(v)); reverse(all(v));

for(int i=0;i<n/2;i++){
    ans+=v[i];
}

cout << ans;

return 0;
}
Copy
Two Teams yumna08
GNU G++17
49 ms
3.2 MB
Accepted