Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pll;
typedef pair<pll,int> pli;

int n;
LL a[100005],b[100005];

priority_queue<pli> pqa,pqb;
bool vis[100005];
LL ans = 0LL;

int main(){
   cin >> n;
   for(int i=1;i<=n;i++) cin >> a[i] >> b[i];
   for(int i=1;i<=n;i++){
      pli tmp;
      tmp.first.first = a[i];
      tmp.first.second = b[i];
      tmp.second = i;
      pqa.push(tmp);
      swap(tmp.first.first,tmp.first.second);
      pqb.push(tmp);
   }
   for(int i=1;i<=n;i++){
      while(vis[pqa.top().second]) pqa.pop();
      while(vis[pqb.top().second]) pqb.pop();
      if(i&1){
         if(pqa.top().first.first > pqb.top().first.first){
            ans+=pqa.top().first.first;
            vis[pqa.top().second] = 1;
         } else if(pqa.top().first.first == pqb.top().first.first){
            if(pqa.top().first.second > pqb.top.first.second) {
               ans+=pqa.top().first.first;
               vis[pqa.top().second] = 1;
            } else {
               ans+=pqb.top().first.second;
               vis[pqb.top().second] = 1;
            }
         } else {
            ans+=pqb.top().first.second;
            vis[pqb.top().second] = 1;
         }
      } else {
         if(pqa.top().first.first < pqb.top().first.first){
            ans-=pqb.top().first.first;
            vis[pqb.top().second] = 1;
         } else if(pqa.top().first.first == pqb.top().first.first){
            if(pqa.top().first.second < pqb.top.first.second) {
               ans-=pqb.top().first.first;
               vis[pqb.top().second] = 1;
            } else {
               ans-=pqa.top().first.second;
               vis[pqa.top().second] = 1;
            }
         } else {
            ans-=pqa.top().first.second;
            vis[pqa.top().second] = 1;
         }
      }
   }
   printf("%lld\n",ans);
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:45: error: invalid use of member function 'std::priority_queue<_Tp, _Sequence, _Compare>::const_reference std::priority_queue<_Tp, _Sequence, _Compare>::top() const [with _Tp = std::pair<std::pair<long long int, long long int>, int>; _Sequence = std::vector<std::pair<std::pair<long long int, long long int>, int>, std::allocator<std::pair<std::pair<long long int, long long int>, int> > >; _Compare = std::less<std::pair<std::pair<long long int, long long int>, int> >; const_reference = const std::pair<std::pair<long long int, long long int>, int>&]' (did you forget the '()' ?)
   34 |             if(pqa.top().first.second > pqb.top.first.second) {
      |                                         ~~~~^~~
      |                                                ()
a.cc:34:49: error: expected ')' before 'first'
   34 |             if(pqa.top().first.second > pqb.top.first.second) {
      |               ~                                 ^~~~~
      |                                                 )
a.cc:50:45: error: invalid use of member function 'std::priority_queue<_Tp, _Sequence, _Compare>::const_reference std::priority_queue<_Tp, _Sequence, _Compare>::top() const [with _Tp = std::pair<std::pair<long long int, long long int>, int>; _Sequence = std::vector<std::pair<std::pair<long long int, long long int>, int>, std::allocator<std::pair<std::pair<long long int, long long int>, int> > >; _Compare = std::less<std::pair<std::pair<long long int, long long int>, int> >; const_reference = const std::pair<std::pair<long long int, long long int>, int>&]' (did you forget the '()' ?)
   50 |             if(pqa.top().first.second < pqb.top.first.second) {
      |                                         ~~~~^~~
      |                                                ()
a.cc:50:49: error: expected ')' before 'first'
   50 |             if(pqa.top().first.second < pqb.top.first.second) {
      |               ~                                 ^~~~~
      |                                                 )