Language: C++

¥#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using pi  = pair<int,int>; // fs: value, sc : pos
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
int get_cost(pi lst,int cpos,int nvalue){
    return nvalue + lst.first - (cpos - lst.second);
}
template<class T, class Func = function<T(T, T)>>
class segtree {
    vector<T> obj;
    int offset;
    Func updater;
    T e;
    int bufsize(int num) {
        int i = 1;
        for (; num + 1 >i; i <<= 1);
        offset = i - 1;
        return (i << 1) - 1;
    }
    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)return e;
        if (a <= l && r <= b)return obj[k];
        else return updater(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
    }
public:
    T query(int a, int b) {//[a,b)
        return query(a, b, 0, 0, offset + 1);
    }
    void updateall(int l = 0, int r = -1) {
        if (r < 0)r = offset + 1;
        l += offset, r += offset;
        do {
            l = (l - 1) >> 1, r = (r - 1) >> 1;
            for (int i = l; i < r; i++)obj[i] = updater(obj[i * 2 + 1], obj[i * 2 + 2]);
        } while (l);
    }
    void update(int k, T &a) {
        k += offset;
        obj[k] = a;
        while (k) {
            k = (k - 1) >> 1;
            obj[k] = updater(obj[k * 2 + 1], obj[k * 2 + 2]);
        }
    }
    segtree(int n, T e, const Func &updater = Func()) :obj(bufsize(n), e), e(e), updater(updater) {}
    segtree(vector<T> &vec, T e, const Func &updater = Func()) :obj(bufsize(vec.size()), e), e(e), updater(updater) {
        copy(vec.begin(), vec.end(), obj.begin() + offset);
        updateall();
    }
    typename vector<T>::reference operator[](int n) {
        return obj[n + offset];
    }
};


signed  main(){
    int N,C;
    cin >> N >> C;
    vector<vector<pi>>dp(2,vector<pi>(N,make_pair(-1LL,-1LL)));
    vector<pi>v(N);
    for(auto& p : v){
        cin >> p.second >> p.first;
    }
    for(int i = 0; i < N; ++i){
        int nvalue = v[i].first;
        int npos   = v[i].second;
        if(i == 0){
            dp[1][0].first  = nvalue - npos;
            dp[1][0].second = npos;
            dp[0][0].first  = 0;
            dp[0][0].second = 0;
            
        } else {
            dp[1][i].first = max(get_cost(dp[1][i-1],npos,nvalue),get_cost(dp[0][i-1],npos, nvalue));
            
            dp[1][i].second = npos;
            dp[0][i] = (dp[0][i-1].first > dp[1][i-1].first ? dp[0][i-1] : dp[1][i-1]);
        }
    }
    vector<vector<pi>>rdp(2,vector<pi>(N,make_pair(-1LL,-1LL)));
    vector<pi> rv = v;
    reverse(rv.begin(),rv.end());
    for(auto& p : rv)
        p.second = C - p.second;
    for(int i = 0; i < N; ++i){
        int nvalue = rv[i].first;
        int npos   = rv[i].second;
        if(i == 0){
            rdp[1][0].first  = nvalue - npos;
            rdp[1][0].second = npos;
            rdp[0][0].first  = 0;
            rdp[0][0].second = 0;
            
        } else {
            rdp[1][i].first = max(get_cost(rdp[1][i-1],npos,nvalue),get_cost(rdp[0][i-1],npos, nvalue));
            rdp[1][i].second = npos;
            rdp[0][i] = (rdp[0][i-1].first > rdp[1][i-1].first ? rdp[0][i-1] : rdp[1][i-1]);
            
        }
    }
    int ans = -1;
    auto maxf = [](pi a, pi b){ return (a.first > b.first ? a : b);};
    pi base = make_pair(0,0);
    auto s1 = segtree<pi>(rdp[1],base,maxf);
    auto s0 = segtree<pi>(rdp[0],base,maxf);
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < 2; ++j){
            auto crt = dp[j][i];
            int range = N - i - 1;
            auto a = s1.query(0,range);
            auto b = s0.query(0,range);
            cmax(ans, crt.first);
            cmax(ans, rdp[j][i].first);
            int cnd = crt.first + a.first - min(crt.second,a.second);
            cmax(cnd, crt.first + b.first - min(crt.second,b.second));
            cmax(ans, cnd);
        }
    }
    cout << max(ans,0LL) << endl;
}



Compiler output:
a.cc:1:1: error: extended character ¥ is not valid in an identifier
    1 | ¥#include<bits/stdc++.h>
      | ^
a.cc:1:2: error: stray '#' in program
    1 | ¥#include<bits/stdc++.h>
      |  ^
a.cc:1:1: error: '\U000000a5' does not name a type
    1 | ¥#include<bits/stdc++.h>
      | ^
a.cc:5:13: error: 'pair' does not name a type
    5 | using pi  = pair<int,int>; // fs: value, sc : pos
      |             ^~~~
a.cc:8:14: error: 'pi' was not declared in this scope
    8 | int get_cost(pi lst,int cpos,int nvalue){
      |              ^~
a.cc:8:25: error: expected primary-expression before 'cpos'
    8 | int get_cost(pi lst,int cpos,int nvalue){
      |                         ^~~~
a.cc:8:34: error: expected primary-expression before 'nvalue'
    8 | int get_cost(pi lst,int cpos,int nvalue){
      |                                  ^~~~~~
a.cc:8:40: error: expression list treated as compound expression in initializer [-fpermissive]
    8 | int get_cost(pi lst,int cpos,int nvalue){
      |                                        ^
a.cc:11:32: error: 'function' does not name a type; did you mean 'union'?
   11 | template<class T, class Func = function<T(T, T)>>
      |                                ^~~~~~~~
      |                                union
a.cc:11:40: error: expected '>' before '<' token
   11 | template<class T, class Func = function<T(T, T)>>
      |                                        ^
a.cc:13:5: error: 'vector' does not name a type
   13 |     vector<T> obj;
      |     ^~~~~~
a.cc:49:19: error: expected ')' before '<' token
   49 |     segtree(vector<T> &vec, T e, const Func &updater = Func()) :obj(bufsize(vec.size()), e), e(e), updater(updater) {
      |            ~      ^
      |                   )
a.cc:53:14: error: expected nested-name-specifier before 'vector'
   53 |     typename vector<T>::reference operator[](int n) {
      |              ^~~~~~
a.cc:53:14: error: expected ';' at end of member declaration
   53 |     typename vector<T>::reference operator[](int n) {
      |              ^~~~~~
      |                    ;
a.cc:53:20: error: expected unqualified-id before '<' token
   53 |     typename vector<T>::reference operator[](int n) {
      |                    ^
a.cc: In member function 'T segtree<T, Func>::query(ll, ll, ll, ll, ll)':
a.cc:25:37: error: 'obj' was not declared in this scope
   25 |         if (a <= l && r <= b)return obj[k];
      |                                     ^~~
a.cc: In member function 'void segtree<T, Func>::updateall(ll, ll)':
a.cc:37:40: error: 'obj' was not declared in this scope
   37 |             for (int i = l; i < r; i++)obj[i] = updater(obj[i * 2 + 1], obj[i * 2 + 2]);
      |                                        ^~~
a.cc: In member function 'void segtree<T, Func>::update(ll, T&)':
a.cc:42:9: error: 'obj' was not declared in this scope
   42 |         obj[k] = a;
      |         ^~~
a.cc: In constructor 'segtree<T, Func>::segtree(ll, T, const Func&)':
a.cc:48:56: error: class 'segtree<T, Func>' does not have any field named 'obj'
   48 |     segtree(int n, T e, const Func &updater = Func()) :obj(bufsize(n), e), e(e), updater(updater) {}
      |                                                        ^~~
a.cc: In function 'int main()':
a.cc:61:5: error: 'cin' was not declared in this scope; did you mean 'cmin'?
   61 |     cin >> N >> C;
      |     ^~~
      |     cmin
a.cc:62:5: error: 'vector' was not declared in this scope
   62 |     vector<vector<pi>>dp(2,vector<pi>(N,make_pair(-1LL,-1LL)));
      |     ^~~~~~
a.cc:62:19: error: 'pi' was not declared in this scope
   62 |     vector<vector<pi>>dp(2,vector<pi>(N,make_pair(-1LL,-1LL)));
      |                   ^~
a.cc:62:41: error: 'make_pair' was not declared in this scope
   62 |     vector<vector<pi>>dp(2,vector<pi>(N,make_pair(-1LL,-1LL)));
      |                                         ^~~~~~~~~
a.cc:62:23: error: 'dp' was not declared in this scope
   62 |     vector<vector<pi>>dp(2,vector<pi>(N,make_pair(-1LL,-1LL)));
      |                       ^~
a.cc:63:15: error: 'v' was not declared in this scope
   63 |     vector<pi>v(N);
      |               ^
a.cc:77:42: error: 'get_cost' cannot be used as a function
   77 |             dp[1][i].first = max(get_cost(dp[1][i-1],npos,nvalue),get_cost(dp[0][i-1],npos, nvalue));
      |                                  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:77:75: error: 'get_cost' cannot be used as a function
   77 |             dp[1][i].first = max(get_cost(dp[1][i-1],npos,nvalue),get_cost(dp[0][i-1],npos, nvalue));
      |                                                                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:77:30: error: 'max' was not declared in this scope; did you mean 'cmax'?
   77 |             dp[1][i].first = max(get_cost(dp[1][i-1],npos,nvalue),get_cost(dp[0][i-1],npos, nvalue));
      |                              ^~~
      |                              cmax
a.cc:83:23: error: 'rdp' was not declared in this scope
   83 |     vector<vector<pi>>rdp(2,vector<pi>(N,make_pair(-1LL,-1LL)));
      |                       ^~~
a.cc:84:16: error: 'rv' was not declared in this scope
   84 |     vector<pi> rv = v;
      |                ^~
a.cc:85:5: error: 'reverse' was not declared in this scope
   85 |     reverse(rv.begin(),rv.end());
      |     ^~~~~~~
a.cc:98:43: error: 'get_cost' cannot be used as a function
   98 |             rdp[1][i].first = max(get_cost(rdp[1][i-1],npos,nvalue),get_cost(rdp[0][i-1],npos, nvalue));
      |                                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:98:77: error: 'get_cost' cannot be used as a function
   98 |             rdp[1][i].first = max(get_cost(rdp[1][i-1],npos,nvalue),get_cost(rdp[0][i-1],npos, nvalue));
      |                                                                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:98:31: error: 'max' was not declared in this scope; did you mean 'cmax'?
   98 |             rdp[1][i].first = max(get_cost(rdp[1][i-1],npos,nvalue),get_cost(rdp[0][i-1],npos, nvalue));
      |                               ^~~
      |                               cmax
a.cc:105:20: error: 'pi' is not a type
  105 |     auto maxf = [](pi a, pi b){ return (a.first > b.first ? a : b);};
      |                    ^~
a.cc:105:26: error: 'pi' is not a type
  105 |     auto maxf = [](pi a, pi b){ return (a.first > b.first ? a : b);};
      |                          ^~
a.cc: In lambda function:
a.cc:105:43: error: request for member 'first' in 'a', which is of non-class type 'int'
  105 |     auto maxf = [](pi a, pi b){ return (a.first > b.first ? a : b);};
      |                                           ^~~~~
a.cc:105:53: error: request for member 'first' in 'b', which is of non-class type 'int'
  105 |     auto maxf = [](pi a, pi b){ return (a.first > b.first ? a : b);};
      |                                                     ^~~~~
a.cc: In function 'int main()':
a.cc:106:7: error: expected ';' before 'base'
  106 |     pi base = make_pair(0,0);
      |       ^~~~~
      |       ;
a.cc:107:25: error: template argument 2 is invalid
  107 |     auto s1 = segtree<pi>(rdp[1],base,maxf);
      |                         ^
a.cc:107:34: error: 'base' was not declared in this scope
  107 |     auto s1 = segtree<pi>(rdp[1],base,maxf);
      |                                  ^~~~
a.cc:108:25: error: template argument 2 is invalid
  108 |     auto s0 = segtree<pi>(rdp[0],base,maxf);
      |                         ^
a.cc:117:45: error: 'min' was not declared in this scope; did you mean 'main'?
  117 |             int cnd = crt.first + a.first - min(crt.second,a.second);
      |                                             ^~~
      |                                             main
a.cc:122:5: error: 'cout' was not declared in this scope
  122 |     cout << max(ans,0LL) << endl;
      |     ^~~~
a.cc:122:13: error: 'max' was not declared in this scope; did you mean 'maxf'?
  122 |     cout << max(ans,0LL) << endl;
      |             ^~~
      |             maxf
a.cc:122:29: error: 'endl' was not declared in this scope
  122 |     cout << max(ans,0LL) << endl;
      |                             ^~~~