Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
    long n, c, x[100007], v[100007], ansr[100007], ansl[100007];
    cin >> n >> c;
    for(int i=0; i<n; i++)
    {
        cin >> x[i+1] >> v[i+1];
    }

    x[n+1] = c;
    x[0] = 0;
    ansr[n+1] = 0;
    ansl[n+1] = 0;
    long s=0, t=0;

    for(int i=0; i<=n; i++){
        s += y[i] - (x[i] - x[i-1]);
        ansl[i] = max(ansl[i-1], s);
    }
    for(int i=n; i>=1; i--){
        t += y[i] - (x[i+1] - x[i]);
        ansr[i] = max(ansr[i+1], t);
    }

    long ansR=0, ansL=0;
    long u=0, v=0, test;

    for(int i=1; i<=n; i++)
    {
        u += y[i] - (x[i] - x[i-1]);
        test = u + ansr[i+1] - x[i];
        test = max(u, test);
        ansR = max(ansR, test);
    }

    for(int i=n; i>=i; i--)
    {
        v += y[i] - (x[i+1] - x[i]);
        test = v + ansl[i-1] - (c - x[i]);
        test = max(v, test);
        ansL = max(ansL, test);
    }

    cout << max(ansR, ansL);


}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:14: error: 'y' was not declared in this scope
   19 |         s += y[i] - (x[i] - x[i-1]);
      |              ^
a.cc:23:14: error: 'y' was not declared in this scope
   23 |         t += y[i] - (x[i+1] - x[i]);
      |              ^
a.cc:28:15: error: conflicting declaration 'long int v'
   28 |     long u=0, v=0, test;
      |               ^
a.cc:5:27: note: previous declaration as 'long int v [100007]'
    5 |     long n, c, x[100007], v[100007], ansr[100007], ansl[100007];
      |                           ^
a.cc:32:14: error: 'y' was not declared in this scope
   32 |         u += y[i] - (x[i] - x[i-1]);
      |              ^
a.cc:40:14: error: 'y' was not declared in this scope
   40 |         v += y[i] - (x[i+1] - x[i]);
      |              ^
a.cc:41:30: error: invalid conversion from 'long int*' to 'long int' [-fpermissive]
   41 |         test = v + ansl[i-1] - (c - x[i]);
      |                ~~~~~~~~~~~~~~^~~~~~~~~~~~
      |                              |
      |                              long int*
a.cc:42:19: error: no matching function for call to 'max(long int [100007], long int&)'
   42 |         test = max(v, test);
      |                ~~~^~~~~~~~~
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:42:19: note:   deduced conflicting types for parameter 'const _Tp' ('long int [100007]' and 'long int')
   42 |         test = max(v, test);
      |                ~~~^~~~~~~~~
/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:42:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int*'
   42 |         test = max(v, test);
      |                ~~~^~~~~~~~~