Source Code
#include<iostream>
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int mod=1e9+7;
const ll INF=1e18;
const double pi=3.14159265358979323846;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
#define Go ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using namespace std;



int main()
{
Go

int n; cin >> n;
vector<pair<ll,ll>>v;

for(int i=0;i<n;i++){
    ll a,b; cin >> a >> b;
    v.pb({a,b});
}
sort(all(v));

ll ans1=0,ans2=0; int k=0,ind=0;
for(int i=n-1;i>=0;i--){
    if(k==n/2){ ind=i; break; }
    k++;
    ans1+=v[i].F;
}
for(int i=0;i<=ind;i++){
    ans1+=v[i].S;
}

k=0,ind=0;
for(int i=n-1;i>=0;i--){
    if(k==n/2){ ind=i; break; }
    k++;
    ans2+=v[i].S;
}
for(int i=0;i<=ind;i++){
    ans2+=v[i].F;
}

cout << max(ans1,ans2);

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