#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
vector<ll> h(n);
vector<pair<ll, ll>> hsort(n);
vector<bool> present(n, true);
for (ll i = 0; i < n; ++i) {
cin >> h[i];
hsort[i].first = h[i];
hsort[i].second = i;
}
sort(hsort.begin(), hsort.end());
if (n == 1) {
cout << "1\n";
return 0;
}
ll ans = 1, isl = 1;
for (ll i = 0; i < n; ++i) {
if (i != 0 && hsort[i].first != hsort[i - 1].first) {
ans = max(ans, isl);
}
ll idx = hsort[i].second;
present[idx] = false;
if (idx == 0) {
isl -= !present[1];
continue;
}
if (idx == n - 1) {
isl -= !present[n - 2];
continue;
}
if (!present[idx - 1] && !present[idx + 1]) {
isl--;
continue;
}
if (present[idx - 1] && present[idx + 1]) {
isl++;
continue;
}
}
ans = max(ans, isl);
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
3088 KB |
Output is correct |
2 |
Correct |
14 ms |
2908 KB |
Output is correct |
3 |
Correct |
17 ms |
3160 KB |
Output is correct |
4 |
Correct |
14 ms |
3084 KB |
Output is correct |
5 |
Correct |
14 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
3668 KB |
Output is correct |
2 |
Correct |
9 ms |
3460 KB |
Output is correct |
3 |
Correct |
14 ms |
3668 KB |
Output is correct |
4 |
Correct |
15 ms |
3420 KB |
Output is correct |
5 |
Correct |
14 ms |
3420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
168 ms |
33364 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
32596 KB |
Output is correct |
2 |
Correct |
181 ms |
32504 KB |
Output is correct |
3 |
Correct |
172 ms |
32596 KB |
Output is correct |
4 |
Correct |
146 ms |
26864 KB |
Output is correct |
5 |
Correct |
146 ms |
26704 KB |
Output is correct |