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

using namespace std;

int main() {
	long long n;
	cin>>n;
	vector<pair<long long,long long>> v1(n);
	vector<pair<long long,long long>> v2(n);
	for(int i=0;i<n;i++){
		long long x,y;
		cin>>x>>y;
		v1[i].first=x;
		v1[i].second=y*-1;
		v2[i].first=y;
		v2[i].second=x*-1;
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	long long sum1=0,sum2=0;
	for(int i=0;i<n;i++){
		if(i>=n/2){
			sum1+=v1[i].first;
			sum2+=v2[i].first;
		}else {
			sum1+=v1[i].second*-1;
			sum2+=v2[i].second*-1;
		}
	}
	// for(int i=0;i<n;i++){
	// 	cout<<v1[i].first<<" "<<v1[i].second<<endl;
	// }
	cout<<max(sum1,sum2)<<endl;
	// cout<<" "<<sum1<<" "<<sum2;
	

	return 0;
}
Copy
Two Teams fakher20
GNU G++17
3 ms
840 KB
Wrong Answer