Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define all(v) (v).begin(),(v).end()
#define clr(t,v) memset(t,(v),sizeof(t))
template<class T1, class T2>ostream& operator<<(ostream& os, const pair<T1, T2>&a)
{
   return os << "(" << a.first << "," << a.second << ")";
}
template<class T>void pv(T a, T b)
{
   for(T i = a; i != b; ++i)
      cout << (*i) << " ";
   cout << endl;
}
template<class T>void chmin(T&a, const T&b)
{
   if(a > b)
      a = b;
}
template<class T>void chmax(T&a, const T&b)
{
   if(a < b)
      a = b;
}
 
int nxint()
{
   int x;
   scanf("%d", &x);
   return x;
}
 
ll x[100005], v[100005];
 
struct pos{
   ll b,  e, d;
   pos(int x, int y, int z):b(x), e(y), d(z){
   }
};
int main()
{
   ll n, C;
   while(cin >> n >> C) {
      rep(i, n)
         cin >> x[i] >> v[i];
      queue<pos> que;
      que.push(pos(0, n - 1, v[0] - x[0]));
      que.push(pos(n - 1, 0, v[n - 1] - C +  x[n - 1]));
      ll ans = max(v[0] - x[0], v[n - 1] - C +  x[n - 1]);
      ans = max(0, ans);
      while(!que.empty()){
         pos p = que.front();
         que.pop();
         if(p.b < p.e){
            ll t = v[p.b + 1] - x[p.b + 1] +  x[p.b];
            que.push(pos(p.b + 1, p.e,  p.d + t));
            ans = max(ans, p.d + t);
            t = v[p.e] - x[p.b] -  (C - x[p.e]);
            que.push(pos(p.e , p.b + 1,  p.d + t));
            ans = max(ans, p.d + t);
         }
         else if(p.b > p.e){
            ll t = v[p.b - 1] - x[p.b] + x[p.b -1];
            que.push(pos(p.b - 1, p.e,  p.d + t));
            ans = max(ans, p.d + t);
            t = v[p.e] - x[p.e] - ( C - x[p.b]);
            que.push(pos(p.e, p.b - 1,  p.d + t));
            ans = max(ans, p.d + t);
         }
 
      }
      cout << ans << endl;
 
 
   }
 
   return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:52:16: error: no matching function for call to 'max(int, ll&)'
   52 |       ans = max(0, ans);
      |             ~~~^~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:52:16: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   52 |       ans = max(0, ans);
      |             ~~~^~~~~~~~
/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:
/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:52:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   52 |       ans = max(0, ans);
      |             ~~~^~~~~~~~