Source Code
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define answer(x) cout << (x ? "YES\n" : "NO\n")
#define test ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; cin >> T; while(T--)
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
using namespace std;

const int N = 200100; 
int n; 
multiset<ll, greater<ll>> lose;  

int main()
{
	go;
	ll sm = 0; 
	cin >> n;
	for(int i=1 ;i  <=n; i++)
	{
		ll fr, sc; 
		cin >> fr >> sc; 
		sm += fr; 
		lose.insert(sc - fr); 
	}
	
	n /= 2; 
	for(ll i : lose) if(n)
		n--,
		sm += i; 
	
	cout << sm; 
}



Copy
Two Teams MuhammedAlajam
GNU G++17
207 ms
10.4 MB
Accepted