Language: C++

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstring>
 
using namespace std;
 
typedef long long LL;
 
const int N = 5000 + 5;
const int M = 200 + 5;
const int INF = 1000000000 + 5;
 
int n, m;
int x[N];
int a[M];
LL tag[N << 2];
LL maxv[N << 2];
vector<pair<int, int> > st[M];
 
void modify(int t, int l, int r, int a, int b, LL v)
{
    if (b < l || r < a) return;
    if (a <= l && r <= b) {
        tag[t] += v;
        maxv[t] += v;
        return;
    }
    if (tag[t]) {
        tag[t << 1] += tag[t];
        maxv[t << 1] += tag[t];
        tag[t << 1 | 1] += tag[t];
        maxv[t << 1 | 1] += tag[t];
        tag[t] = 0;
    }
    int mid = (l + r) >> 1;
    modify(t << 1, l, mid, a, b, v);
    modify(t << 1 | 1, mid + 1, r, a, b, v);
    maxv[t] = max(maxv[t << 1], maxv[t << 1 | 1]);
}
 
LL query(int t, int l, int r, int a, int b)
{
    if (b < l || r < a) return 0;
    if (a <= l && r <= b) {
        return maxv[t];
    }
    if (tag[t]) {
        tag[t << 1] += tag[t];
        maxv[t << 1] += tag[t];
        tag[t << 1 | 1] += tag[t];
        maxv[t << 1 | 1] += tag[t];
        tag[t] = 0;
    }
    int mid = (l + r) >> 1;
    return max(query(t << 1, l, mid, a, b), query(t << 1 | 1, mid + 1, r, a, b));
}
 
void solve()
{
    cin >> n >> m;
    for(int i = 0; i < n - 1; ++ i) {
        scanf("%d", x + i);
    }
 
    long long ans = 0;
    for(int j = 0; j < m; ++ j) {
        st[j].push_back(make_pair(INF, -1));
    }
 
    for(int i = 0; i < n; ++ i) {
        long long tmp = 0;
        for(int j = 0; j < m; ++ j) {
            scanf("%d", a + j);
            tmp += a[j];
        }
        ans = max(ans, tmp);
 
        for(int j = 0; j < m; ++ j) {
             while (a[j] >= st[j].back().first) {
                    int r = st[j].back().second;
                    int v = st[j].back().first;
                    st[j].pop_back();
                    int l = st[j].back().second + 1;
                    modify(1, 0, n - 1, l, r, -v);
                } else {
                    break;
                }
            }
            modify(1, 0, n - 1, st[j].back().second + 1, i, a[j]);
            st[j].push_back(make_pair(a[j], i));
        }
 
        if (i > 0) {
            modify(1, 0, n - 1, 0, i - 1, -x[i - 1]);
        }
        ans = max(ans, query(1, 0, n - 1, 0, i));
    }
    cout << ans << endl;
}
 
int main()
{
    solve();
    return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:89:19: error: 'else' without a previous 'if'
   89 |                 } else {
      |                   ^~~~
a.cc:93:36: error: 'j' was not declared in this scope
   93 |             modify(1, 0, n - 1, st[j].back().second + 1, i, a[j]);
      |                                    ^
a.cc:97:13: error: 'i' was not declared in this scope
   97 |         if (i > 0) {
      |             ^
a.cc:100:46: error: 'i' was not declared in this scope
  100 |         ans = max(ans, query(1, 0, n - 1, 0, i));
      |                                              ^
a.cc: At global scope:
a.cc:102:5: error: 'cout' does not name a type
  102 |     cout << ans << endl;
      |     ^~~~
a.cc:103:1: error: expected declaration before '}' token
  103 | }
      | ^