Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>

using ll = long long;

using namespace std;

struct section{long l, r;};

using pq = priority_queue<int, vector<int>, function<bool(int, int)>> ;

section s[100010];
int n;

long journey(bool di, pq ql, pq qr) {
    long res = 0, prev = 0;
    for (int i=0; i<n; i++) {
        if (di && !ql.empty()) {
            int j = ql.top(); ql.pop();
            if (s[j].l > prev) {
                res += s[j].l - prev;
                prev = s[j].l;
                di = !di;
            } else 
                break;
        } else if (!qr.empty()) {
            int j = qr.top(); qr.pop();
            if (s[j].r < prev) {
                res -= s[j].r - prev;
                prev = s[j].r;
                di = !di;
            } else 
                break;
        }
    }
    return res + abs(prev);
}

int main() {
    cin >> n;
    for (int i=0; i<n; i++) cin >> s[i].l >> s[i].r;
    pq ql(
        [&](int a, int b) {
            return s[a].l < s[b].l;
        }
    );
    pq qr(
        [&](int a, int b) {
            return s[a].r > s[b].r;
        }
    );
    for (int i=0; i<n; i++) (ql.push(i), qr.push(i));
    cout << max(journey(true, ql, qr), journey(false, ql, qr)) << '\n';
    return 0;
}

Compiler output:
a.cc:14:45: error: 'function' was not declared in this scope
   14 | using pq = priority_queue<int, vector<int>, function<bool(int, int)>> ;
      |                                             ^~~~~~~~
a.cc:7:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
    6 | #include <cmath>
  +++ |+#include <functional>
    7 | 
a.cc:14:67: error: expression list treated as compound expression in functional cast [-fpermissive]
   14 | using pq = priority_queue<int, vector<int>, function<bool(int, int)>> ;
      |                                                                   ^
a.cc:14:68: error: template argument 3 is invalid
   14 | using pq = priority_queue<int, vector<int>, function<bool(int, int)>> ;
      |                                                                    ^~
a.cc:19:23: error: 'pq' has not been declared
   19 | long journey(bool di, pq ql, pq qr) {
      |                       ^~
a.cc:19:30: error: 'pq' has not been declared
   19 | long journey(bool di, pq ql, pq qr) {
      |                              ^~
a.cc: In function 'long int journey(bool, int, int)':
a.cc:22:23: error: request for member 'empty' in 'ql', which is of non-class type 'int'
   22 |         if (di && !ql.empty()) {
      |                       ^~~~~
a.cc:23:24: error: request for member 'top' in 'ql', which is of non-class type 'int'
   23 |             int j = ql.top(); ql.pop();
      |                        ^~~
a.cc:23:34: error: request for member 'pop' in 'ql', which is of non-class type 'int'
   23 |             int j = ql.top(); ql.pop();
      |                                  ^~~
a.cc:30:24: error: request for member 'empty' in 'qr', which is of non-class type 'int'
   30 |         } else if (!qr.empty()) {
      |                        ^~~~~
a.cc:31:24: error: request for member 'top' in 'qr', which is of non-class type 'int'
   31 |             int j = qr.top(); qr.pop();
      |                        ^~~
a.cc:31:34: error: request for member 'pop' in 'qr', which is of non-class type 'int'
   31 |             int j = qr.top(); qr.pop();
      |                                  ^~~
a.cc: In function 'int main()':
a.cc:46:5: error: 'pq' was not declared in this scope
   46 |     pq ql(
      |     ^~
a.cc:50:5: error: expected primary-expression before ')' token
   50 |     );
      |     ^
a.cc:51:7: error: expected ';' before 'qr'
   51 |     pq qr(
      |       ^~~
      |       ;
a.cc:55:5: error: expected primary-expression before ')' token
   55 |     );
      |     ^
a.cc:56:30: error: 'ql' was not declared in this scope; did you mean 'll'?
   56 |     for (int i=0; i<n; i++) (ql.push(i), qr.push(i));
      |                              ^~
      |                              ll
a.cc:56:42: error: 'qr' was not declared in this scope
   56 |     for (int i=0; i<n; i++) (ql.push(i), qr.push(i));
      |                                          ^~
a.cc:57:31: error: 'ql' was not declared in this scope; did you mean 'll'?
   57 |     cout << max(journey(true, ql, qr), journey(false, ql, qr)) << '\n';
      |                               ^~
      |                               ll
a.cc:57:35: error: 'qr' was not declared in this scope
   57 |     cout << max(journey(true, ql, qr), journey(false, ql, qr)) << '\n';
      |                                   ^~