#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n; cin >> n;
vector<ll> a(n); for (auto &x: a) cin >> x;
auto f = [&](double h) {
ll ans = 0;
bool curr = false;
for (ll i = 0; i < n; i++)
if (a[i] > h) {
if (!curr) ans++;
curr = true;
} else curr = false;
return ans;
};
ll mx = *max_element(a.begin(), a.end());
ll best = 0;
double l = 0, r = 2e31;
while (r - l > 0.1) {
double m1 = l + (r - l) / 3.0;
double m2 = r - (r - l) / 3.0;
if (f(m1) < f(m2)) l = m1;
else r = m2;
}
cout << max(f(l), max(f(l - 1), f(l + 1)));
}
# | 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... |