Source Code
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define t int t;cin>>t; while(t--)
#define out(a,n) for(int i=0;i<n;i++){cout<<a[i]<< " ";}
#define FAST ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
using pll = pair<ll, ll>;
int main ()
{
    FAST;
    // t
    {
        ll n;
        cin>>n;
        vector<pair<int,int> >v,vv;
        ll x,y;
        while(n--)
        {
            cin>>x>>y;
            v.pb({x,y});
            vv.pb({y,x});
        }

        sort(v.begin(),v.end());
        sort(vv.begin(),vv.end());
        reverse(v.begin(),v.end());
        reverse(vv.begin(),vv.end());
        /*for (int i=0;i<v.size();i++)
        {
            cout<<v[i].first<< " "<<v[i].second<<endl;
        }
        cout<<"----------------"<<endl;
         for (int i=0;i<vv.size();i++)
        {
            cout<<vv[i].first<< " "<<vv[i].second<<endl;
        }*/
        ll s1=0,s2=0;
        for (int i=0; i<v.size()/2; i++)
        {
            s1+=v[i].first;
        }
        for (int i=0; i<vv.size()/2; i++)
        {
            s2+=vv[i].first;
        }
        // cout<<s1<<" "<<s2<<endl;

        for (int i=v.size()/2; i<v.size(); i++)
        {
            s1+=v[i].second;
        }


        for (int i=vv.size()/2; i<vv.size(); i++)
        {
            s2+=vv[i].second;
        }
        cout<<max(s1,s2)<<endl;


    }

}
Copy
Two Teams Ann_Sam65
GNU G++17
3 ms
1.0 MB
Wrong Answer