Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

int main(){
    int N;
    int64_t C;
    cin >> N >> C;

    vector<int64_t> x(N), v(N);
    vector<int64_t> x2(N), v2(N);
    for(int i = 0; i < N; ++i){
        cin >> x[i] >> v[i];
        x2[i] = C - x[i];
        v2[i] = v[i];
    }
    v[0] -= x[0];
    int64_t ans = 0;
    ans = max(ans, v[0]);
    //cout << v[0] << endl;
    for(int i = 1; i < N; ++i){
        v[i] += x[i-1];
        v[i] -= x[i];
        v[i] += v[i-1];
        //cout << v[i] << endl;
        ans = max(ans, v[i]);
    }
    v2[N-1] -= x2[N-1];
    ans = max(ans, v2[N-1]);
    /*cout << "po" << endl;
    cout << v2[N-1] << endl;*/
    for(int i = N-2; i >= 0; --i){
        v2[i] += x2[i+1];
        v2[i] -= x2[i];
        v2[i] += v2[i+1];
        //cout << v2[i] << endl;
        ans = max(ans, v2[i]);
    }
    vector<int64_t> vm(N), vm2(N);
    vm[0] = max(0ll, v[0]);
    for(int i = 1; i < N; ++i){
        vm[i] = max(v[i], vm[i-1]);
    }
    vm2[N-1] = max(0ll, v2[N-1]);
    for(int i = N-2; i >= 0; --i){
        vm2[i] = max(v2[i], vm2[i+1]);
    }

    for(int i = 0; i < N-1; ++i){
        int64_t sum = v[i] - x[i] + vm2[i+1];
        ans = max(ans, sum);
    }
    for(int i = 1; i < N; ++i){
        int64_t sum = v2[i] - x2[i] + vm[i-1];
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:16: error: no matching function for call to 'max(long long int, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&)'
   47 |     vm[0] = max(0ll, v[0]);
      |             ~~~^~~~~~~~~~~
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:47:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   47 |     vm[0] = max(0ll, v[0]);
      |             ~~~^~~~~~~~~~~
/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:47:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   47 |     vm[0] = max(0ll, v[0]);
      |             ~~~^~~~~~~~~~~
a.cc:51:19: error: no matching function for call to 'max(long long int, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&)'
   51 |     vm2[N-1] = max(0ll, v2[N-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:51:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   51 |     vm2[N-1] = max(0ll, v2[N-1]);
      |                ~~~^~~~~~~~~~~~~~
/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
/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:51:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   51 |     vm2[N-1] = max(0ll, v2[N-1]);
      |                ~~~^~~~~~~~~~~~~~