Source Code
#include <iostream>
#include <algorithm>
#include <vector>
#define  speed 	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

vector<int>v;

void solve() {
	int n, x, y;
	long long ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x >> y;
		ans += y;
		v.push_back(x - y);
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	for (int i = 0; i < n / 2; i++) {
		ans += v[i];
	}
	cout << ans;
}

int main() {
	speed
		int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
Copy
Two Teams lafi-Odeh
GNU G++17
49 ms
2.1 MB
Accepted