#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, lo = 0, hi = 2e18, best = 0; cin >> n;
    vector<ll> a(n); for (auto &x: a) cin >> x;
    function<ll(ll)> f = [&](ll h) {
        bool curr = false; ll ans = 0;
        for (ll i = 0; i < n; i++) {
            if (a[i] > h) {
                if (!curr) ans++, curr = true;
            } else curr = false;
        }
        return ans;
    };
    
    while (hi - lo > 3) {
        ll m1 = lo + (hi - lo) / 3;
        ll m2 = hi - (hi - lo) / 3;
        if (f(m1) < f(m2)) lo = m1 + 1;
        else hi = m2 - 1;
    }
    for (ll h = lo; h <= hi; h++) best = max(best, f(h));
    cout << best << "\n";
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |