Source Code
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define p1 2*p
#define p2 p1+1
#define ll long long
#define pb push_back
#define LFT p1,L,Mid
#define pf push_front
#define Mid ((L+R)/2)
#define RGT p2,Mid+1,R
#define pi pair<int,int>
#define pii pair<pi,pi>
#define deb(x) cout<<#x<<"="<<x<<endl
#define go ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int n;
ll ans;
pi a[200200];
bool com1(pi A,pi B)
{
    return A.F-A.S>B.F-B.S;
}
bool com2(pi A,pi B)
{
    return A.F-A.S<B.F-B.S;
}
int main()
{
    go;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i].F>>a[i].S;
    sort(a,a+n,com1);
    for(int i=0;i<n/2;i++)
        ans+=a[i].F;
    for(int i=n/2;i<n;i++)
        ans+=a[i].S;
    ll ans1=0;
    sort(a,a+n,com2);
    for(int i=0;i<n/2;i++)
        ans1+=a[i].S;
    for(int i=n/2;i<n;i++)
        ans1+=a[i].F;
    cout<<max(ans,ans1);
    return 0;
}
Copy
Two Teams Grapeee
GNU G++17
85 ms
2.6 MB
Accepted