Source Code
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n, x, y;
	ll s1 = 0, s2 = 0,s3=0,s4=0;
	cin >> n;
	vector<pair<int, int>> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i].first >> v[i].second;
		v[i].second*=-1;
	}
	sort(v.rbegin(), v.rend());
	for (int i = 0; i < n / 2; i++)
	{
		s1 += v[i].first;
		swap(v[i].first, v[i].second);
		v[i].first*=-1,v[i].second*=-1;
	}
	for (int i = n / 2; i < n; i++)
	{
		s2 += -v[i].second;
		swap(v[i].first, v[i].second);
		v[i].first*=-1,v[i].second*=-1;
	}
	sort(v.rbegin(),v.rend());
	for (int i = 0; i < n / 2; i++)
	{
		s4 += v[i].first;
	}
	for (int i = n / 2; i < n; i++)
	{
		s3 += -v[i].second;
	}
	cout<<max(s1+s2,s3+s4);
}
Copy
Two Teams Amrharb
GNU G++17
3 ms
848 KB
Wrong Answer