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;
		v2[i].first=y;
		v2[i].second=x;
	}
	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;
			sum2+=v2[i].second;
		}
	}
	cout<<max(sum1,sum2);
	

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