Language: C++

#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,c;cin>>n>>c;
    vector<pll> xv(n);
    vector<pair<pll,pll> >memo(n+1);
    rep(i,n){
        ll x,v;cin>>x>>v;
        xv[i]=mp(x,v);
    }
    ll ma1=0,ma2=0;
    ll cnt1=0,cnt2=0;
    ll k=0LL;
    rep(i,n){
        cnt1+=xv[i].second-(xv[i].first-k);
        ma1=max(ma1,cnt1);
        memo[i+1].first.first=ma1;
        memo[i+1].first.second=xv[i].first;
        k=xv[i].first;
    }
    reverse(all(xv));
    k=0LL;
    rep(i,n){
        cnt2+=xv[i].second-(c-xv[i].first-k);
        ma2=max(ma2,cnt2);
        memo[n-i].second.first=ma2;
        memo[n-i].second.second=c-xv[i].first;
        k=c-xv[i].first;
    }
    ll ma=0;
    REP(i,1,n){
        ma=max({memo[i].first.first,memo[i+1].first.first-memo[i].first.second+memo[i+1].second.first
        ,memo[i].second.first-memo.second.second+memo[i].first.first,memo.second.first});
    }
    cout<<ma<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:36: error: 'class std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >' has no member named 'second'
   44 |         ,memo[i].second.first-memo.second.second+memo[i].first.first,memo.second.first});
      |                                    ^~~~~~
a.cc:44:75: error: 'class std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >' has no member named 'second'
   44 |         ,memo[i].second.first-memo.second.second+memo[i].first.first,memo.second.first});
      |                                                                           ^~~~~~
a.cc:43:15: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   43 |         ma=max({memo[i].first.first,memo[i+1].first.first-memo[i].first.second+memo[i+1].second.first
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   44 |         ,memo[i].second.first-memo.second.second+memo[i].first.first,memo.second.first});
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:   candidate expects 2 arguments, 1 provided
/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, 1 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:   template argument deduction/substitution failed:
/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:   candidate expects 2 arguments, 1 provided