Source Code
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> p(n),c(n);
	vector<pair<int,int>> d;
	// d.second = p->0 OR c->1
	int cc = n/2;
	int pp = n/2;
	for(int i=0; i<n; i++){
		cin>>p[i]>>c[i];
		d.push_back({p[i]-c[i],i});
	}
	sort(d.rbegin(),d.rend());
	int total = 0;
	int i, j;
	i = 0;
	j = d.size() - 1;
	while (i<j){
		total += p[d[i].second];
		total += c[d[j].second];
		i++; j--;
	}
	cout << total << endl;
	return 0;
}
Copy
Two Teams Saq
GNU G++17
2 ms
932 KB
Wrong Answer