This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n;
cin >> n;
vector<pll> heights(n);
for (ll i = 0; i < n; i++)
{
cin >> heights[i].first;
heights[i].second = i;
}
sort(heights.begin(), heights.end(), greater<pll>());
vector<bool> used(n, false);
ll ans = 0, curr = 0;
for (ll i = 0; i < n; i++)
{
ll ind = heights[i].second;
used[ind] = true;
if (i < n - 1 && heights[i].first == heights[i + 1].first) continue;
if ((ind == 0 || (!used[ind - 1])) && (ind == n - 1 || (!used[ind + 1])))
curr++;
if (ind && ind < n - 1 && used[ind - 1] && used[ind + 1])
curr--;
ans = max(ans, curr);
}
cout << ans;
}
# | 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... |