Language: C++

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)    for(int (i) = 0;   (i) < (n); ++(i))
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))

int N;
vector<int> A;

void extend(vector<pair<int, int>> &v, int sz) {
    if (v.size() == 0) v.emplace_back(0, sz);
    else if (v.back().second == 0) v.back().first += sz;
    else v.emplace_back(0, sz);
}

bool increment(int mid, vector<pair<int, int>> &v) {
    if ((int)v.size() == 1) {
        if (v[0].first == mid - 1) return false;
        if (v[0].second == 1) v[0].first++;
        else {
            pair<int, int> nw = {v[0].first + 1, 1};
            v[0].second--;
            v.emplace_back(nw);
        }
        return true;
    }
    if (v.back().first == mid - 1) {
        pair<int, int>    bck = v.back();   v.pop_back();   bck.first = 0;
        pair<int, int> bckbck = v.back();   v.pop_back();
        if (bckbck.second == 1) {
            bckbck.first++;
            v.emplace_back(bckbck);
        } else {
            pair<int, int> nw = {bckbck.first + 1, 1};
            bckbck.second--;
            v.emplace_back(bckbck);
            v.emplace_back(nw);
        }
        v.emplace_back(bck);
    } else {
        if (v.back().second == 1) {
            v.back().first++;
        } else {
            pair<int, int> nw = {v.back().first + 1, 1};
            v.back().second--;
            v.emplace_back(nw);
        }
    }
    return true;
}

void cut(vector<pair<int, int>> &v, int bef, int aft) {
    while (bef > aft) {
        assert(v.size() >= 1);
        if (bef - aft >= v.back().second) {
            bef -= v.back().second;
            v.pop_back();
        } else {
            int sz = bef - aft;
            v.back().second -= sz;
            bef -= sz;
        }
    }
}

void print(vector<pair<int, int>> &v) {
    cerr << v.size() << endl;
    for (auto& p: v) {
        cerr << p.first << ' ' << p.second << endl;
    }
    cerr << endl;
}

/*
    ランレングス圧縮した状態で操作を行う
    文字数を増やすときは, 最後に0をその個数分つなげる
    文字数が同じときは, 最後の要素をインクリメントする
    文字数を減らすときは, その文字数まで減らしてからインクリメントする
*/
bool check(int mid) {
    vector<pair<int, int>> arr;
    extend(arr, A[0]);
    FOR(i, 1, N) {
        int bef = A[i - 1];
        int aft = A[i];
        if (bef < aft) {
            extend(arr, aft - bef);
        } else if (bef == aft) {
            if (not increment(mid, arr)) return false;
        } else {
            cut(arr, bef, aft);
            if (not increment(mid, arr)) return false;
        }
    }
    return true;
}

signed main() {

    cin >> N;

    A.resize(N);
    REP(i, N) cin >> A[i];

    ll ok = (ll)1e18 + 10, ng = 0;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) >> 1;
        if (check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << ok << endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:104:5: error: 'll' was not declared in this scope
  104 |     ll ok = (ll)1e18 + 10, ng = 0;
      |     ^~
a.cc:105:16: error: 'ok' was not declared in this scope
  105 |     while (abs(ok - ng) > 1) {
      |                ^~
a.cc:105:21: error: 'ng' was not declared in this scope
  105 |     while (abs(ok - ng) > 1) {
      |                     ^~
a.cc:106:11: error: expected ';' before 'mid'
  106 |         ll mid = (ok + ng) >> 1;
      |           ^~~~
      |           ;
a.cc:107:19: error: 'mid' was not declared in this scope
  107 |         if (check(mid)) {
      |                   ^~~
a.cc:114:13: error: 'ok' was not declared in this scope
  114 |     cout << ok << endl;
      |             ^~