Language: C++

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N;
vector<int> A;

void init()
{
	cin >> N;
	CINV(A, N);
}

int X;

inline void add(int x, map<int, int>& m)
{
	m[x]++;
	if (m[x] == X) {
		m.erase(x);
		add(x-1, m);
	}
}

inline bool isok(int x)
{
	X = x;
	int pre = 0;
	map<int, int> m;
	rep(i, N) {
		if (pre < A[i]) {
			pre = A[i];
			continue;
		}
		pre = A[i];
		add(A[i], m);
		while (1) {
			auto itr = m.rbegin();
			int x = (*itr).first;
			if (x > A[i]) m.erase(itr);
			else break;
		}
		if (m.count(0)) return false;
	}
	return true;
}

void solve()
{
	bool f = true;
	rep(i, N-1) {
		f &= A[i] < A[i+1];
	}
	if (f) {
		cout << 1 << endl;
		return;
	}
	int ok = 1000000000;
	int ng = 1;
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		if (isok(mid)) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}





Compiler output:
a.cc: In function 'bool isok(int)':
a.cc:75:46: error: no matching function for call to 'std::map<int, int>::erase(std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const int, int> > >&)'
   75 |                         if (x > A[i]) m.erase(itr);
      |                                       ~~~~~~~^~~~~
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:1080:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::erase(const_iterator) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; iterator = std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator; const_iterator = std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::const_iterator]'
 1080 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_map.h:1080:28: note:   no known conversion for argument 1 from 'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const int, int> > >' to 'std::map<int, int>::const_iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::const_iterator'}
 1080 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_map.h:1086:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::erase(iterator) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; iterator = std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator]'
 1086 |       erase(iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_map.h:1086:22: note:   no known conversion for argument 1 from 'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const int, int> > >' to 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'}
 1086 |       erase(iterator __position)
      |             ~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_map.h:1117:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::size_type std::map<_Key, _Tp, _Compare, _Alloc>::erase(const key_type&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; size_type = long unsigned int; key_type = int]'
 1117 |       erase(const key_type& __x)
      |       ^~~~~
/usr/include/c++/14/bits/stl_map.h:1117:29: note:   no known conversion for argument 1 from 'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const int, int> > >' to 'const std::map<int, int>::key_type&' {aka 'const int&'}
 1117 |       erase(const key_type& __x)
      |             ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:1137:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::erase(const_iterator, const_iterator) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; iterator = std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator; const_iterator = std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::const_iterator]'
 1137 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_map.h:1137:7: note:   candidate expects 2 arguments, 1 provided