Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Node{
    public:
        Node(int _id, int _x):id(_id),x(_x){}
        int id;
        int x;
        bool operator<(const Node &node) const{
            return x<node.x;
        }
};

long long int walk(int p, const int n, const vector<Node> l, const vector<Node> r, vector<int> color){
    int pl = n-1;
    int pr = 0;
    long long int td = 0;
    for(int i=0;i<n;++i){
        while(pl>=0 && color[l[pl].id]==1){
            --pl;
        }
        while(pr<n && color[r[pr].id]==1){
            ++pr;
        }
        int ld = 0;
        int rd = 0;
        if(pl>=0){
            int x = l[pl].x;
            if(x>=p){
               ld = x-p; 
            }
        }
        if(pr<n){
            int x = r[pr].x;
            if(p>=x)
                rd = p-x;
        }
        if(pl>=0 && ld>=rd){
            p += ld;
            td += ld;
            color[l[pl].id] = 1;
            --pl;
        }
        else if(pr<n){
            p -= rd;
            td += rd;
            color[r[pr].id] = 1;
            ++pr;
        }
        //cout<<p<<" "<<td<<endl;
    }
    td+=abs(p);
    return td;
}
int main(){
    vector<Node> l;
    vector<Node> r;
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        int x,y;
        cin>>x>>y;
        l.push_back(Node(i,x));
        r.push_back(Node(i,y));
    }
    sort(l.begin(),l.end());
    sort(r.begin(),r.end());
    vector<int> color(n);
    
    
    int p = 0;
    if(l[n-1].x>0){
        p = l[n-1].x;
        color[l[n-1].id] = 1;
    }
    int td1 = walk(p,n,l,r,color) + p;
    //fill(color.begin(),color.end(),0);
    for(int i=0;i<color.size();++i)
        color[i] = 0;
    p = 0;
    if(r[0].x<0){
        p = r[0].x;
        color[r[0].id] = 1;
    }
    long long int td2 = walk(p,n,l,r,color) - p;
    long long int td = max(td1,td2);
    cout<<td<<"\n";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:87:27: error: no matching function for call to 'max(int&, long long int&)'
   87 |     long long int td = max(td1,td2);
      |                        ~~~^~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:87:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   87 |     long long int td = max(td1,td2);
      |                        ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:87:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   87 |     long long int td = max(td1,td2);
      |                        ~~~^~~~~~~~~