#include <bits/stdc++.h>
using namespace std;
#define DEMON_SLAYER ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main() {
DEMON_SLAYER
int n;
cin >> n;
int prev = -1;
vector<pair<int, int>> v;
int cur = 0;
int arr[n];
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (prev == a) {
continue;
}
v.push_back({a, cur});
prev = a;
arr[cur] = a;
cur++;
}
sort(v.begin(), v.end(), greater<pair<int, int>>());
if (v.size() == 1) {
cout << 1;
return 0;
}
int ans = 0;
int actans = 0;
for (int i = 0; i < cur; i++) {
pair<int, int> c = v[i];
if (c.second == cur - 1) {
if (arr[c.second - 1] <= c.first) {
ans++;
}
} else if (c.second == 0) {
if(arr[c.second + 1] < c.first) {
ans++;
}
} else {
if (arr[c.second - 1] > c.first && arr[c.second + 1] > c.first) {
ans--;
} else if (arr[c.second - 1] < c.first && arr[c.second + 1] < c.first) {
ans++;
}
}
if (i == cur - 1 || v[i].first != v[i + 1].first) {
actans = max(actans, ans);
}
}
cout << actans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2268 KB |
Output is correct |
2 |
Correct |
14 ms |
2268 KB |
Output is correct |
3 |
Correct |
17 ms |
2268 KB |
Output is correct |
4 |
Correct |
14 ms |
2268 KB |
Output is correct |
5 |
Correct |
14 ms |
2012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
2524 KB |
Output is correct |
2 |
Correct |
13 ms |
2420 KB |
Output is correct |
3 |
Correct |
16 ms |
2520 KB |
Output is correct |
4 |
Correct |
16 ms |
2520 KB |
Output is correct |
5 |
Correct |
15 ms |
2600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
21848 KB |
Output is correct |
2 |
Correct |
179 ms |
21652 KB |
Output is correct |
3 |
Correct |
172 ms |
21828 KB |
Output is correct |
4 |
Correct |
178 ms |
21688 KB |
Output is correct |
5 |
Correct |
173 ms |
20916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
180 ms |
21212 KB |
Output is correct |
2 |
Correct |
179 ms |
20924 KB |
Output is correct |
3 |
Correct |
180 ms |
20924 KB |
Output is correct |
4 |
Correct |
154 ms |
16068 KB |
Output is correct |
5 |
Correct |
158 ms |
15028 KB |
Output is correct |