#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int arr[n];
for (int i=0;i<n;i++) cin>>arr[i];
if (n<2){
cout<<1;
return 0;
}
vector<pair<int,bool> > peaks; //height,true=bottom,false=top
bool increasing;
if (arr[1]>arr[0]){
peaks.push_back(make_pair(arr[1],false));
increasing=true;
}
else {
peaks.push_back(make_pair(arr[0],false));
peaks.push_back(make_pair(arr[1],true));
increasing=false;
}
for (int i=2;i<n;i++){
if (increasing){
if (arr[i]>=arr[i-1]){
peaks.pop_back();
peaks.push_back(make_pair(arr[i],false));
}
else {
peaks.push_back(make_pair(arr[i],true));
increasing=false;
}
}
else {
if (arr[i]<=arr[i-1]){
peaks.pop_back();
peaks.push_back(make_pair(arr[i],true));
}
else {
peaks.push_back(make_pair(arr[i],false));
increasing=true;
}
}
}
if (peaks.back().second==true) peaks.pop_back();
sort(peaks.begin(),peaks.end());
int total=0,maxi=0;
for (int i=peaks.size()-1;i>=0;i--){
if (peaks[i].second) total--;
else total++;
maxi=max(maxi,total);
}
cout<<maxi;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
1656 KB |
Output is correct |
2 |
Correct |
15 ms |
1656 KB |
Output is correct |
3 |
Correct |
15 ms |
1660 KB |
Output is correct |
4 |
Correct |
16 ms |
1784 KB |
Output is correct |
5 |
Correct |
16 ms |
1692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2676 KB |
Output is correct |
2 |
Correct |
21 ms |
2540 KB |
Output is correct |
3 |
Correct |
24 ms |
2672 KB |
Output is correct |
4 |
Correct |
24 ms |
2676 KB |
Output is correct |
5 |
Correct |
23 ms |
2676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
237 ms |
21956 KB |
Output is correct |
2 |
Correct |
244 ms |
22080 KB |
Output is correct |
3 |
Correct |
239 ms |
21952 KB |
Output is correct |
4 |
Correct |
237 ms |
22084 KB |
Output is correct |
5 |
Correct |
224 ms |
21348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
226 ms |
21456 KB |
Output is correct |
2 |
Correct |
228 ms |
21424 KB |
Output is correct |
3 |
Correct |
239 ms |
21344 KB |
Output is correct |
4 |
Correct |
149 ms |
15524 KB |
Output is correct |
5 |
Correct |
142 ms |
15428 KB |
Output is correct |