Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long (i)=(0);(i)<(long long)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n, c;
    cin >> n >> c;
    vector<ll> x(n), v(n);
    rep(i, n) cin >> x[i] >> v[i];

    vector<ll> dp1(n, 0), dp2(n, 0);
    dp1[0] = v[0] - x[0];
    for (int i=1; i<n; ++i) dp1[i] = dp1[i-1]+v[i]-(x[i]-x[i-1]);
    for (int i=1; i<n; ++i) dp1[i] = max(dp1[i], dp1[i-1]);

    dp2[n-1] = v[n-1] - (c - x[n-1]);
    for (int i=n-2; i>=0; --i) dp2[i] = dp2[i+1]+v[i]-(x[i+1]-x[i]);
    for (int i=n-2; i>=0; --i) dp2[i] = max(dp2[i], dp2[i+1]);

    ll ans = max(0LL, dp2[0]);
    rep(i, n) {
        int tmp = dp1[i];
        if (i+1<n and dp2[i+1]-x[i]>0) tmp += dp2[i+1] - x[i];
        ans = max(ans, tmp);
    }
    for (int i=n-1; i>=0; --i) {
        int tmp = dp2[i];
        if (i >= 1 and dp1[i-1] - (c - x[i]) > 0) tmp += dp1[i-1] - (c - x[i]);
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:18: error: no matching function for call to 'max(ll&, int&)'
   34 |         ans = max(ans, tmp);
      |               ~~~^~~~~~~~~~
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:34:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   34 |         ans = max(ans, tmp);
      |               ~~~^~~~~~~~~~
/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:34:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   34 |         ans = max(ans, tmp);
      |               ~~~^~~~~~~~~~
a.cc:39:18: error: no matching function for call to 'max(ll&, int&)'
   39 |         ans = max(ans, tmp);
      |               ~~~^~~~~~~~~~
/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:39:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   39 |         ans = max(ans, tmp);
      |               ~~~^~~~~~~~~~
/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:39:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   39 |         ans = max(ans, tmp);
      |               ~~~^~~~~~~~~~