岛
作者:
silva31
,
2024-03-05 14:07:24
,
所有人可见
,
阅读 38
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int h[N];
int n;
typedef pair<int, int> P;
P p[N];
int main()
{
cin>>n;
for(int i = 1; i <= n; i ++)
{
cin>>h[i];
}
int cnt = unique(h + 1, h + n + 1) - (h + 1);
h[cnt + 1] = 0;
for(int i = 1; i <= cnt; i ++)
{
p[i] = {h[i], i};
}
sort(p + 1, p + cnt + 1);
int ans = 1, res = 1;
for(int i = 1; i <= cnt; i ++)
{
int index = p[i].second;
if(h[index - 1] > h[index] && h[index + 1] > h[index]) res += 1;
if(h[index - 1] < h[index] && h[index + 1] < h[index]) res -= 1;
if(p[i].first != p[i+1].first)
{
ans = max(ans, res);
}
}
cout<<ans<<endl;
}