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 <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> h(n);
vector<pair<int, int>> hsort(n);
vector<bool> present(n, true);
for (int 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;
}
int ans = 1, isl = 1;
for (int i = 0; i < n; ++i) {
if (i != 0 && hsort[i].first != hsort[i - 1].first) {
ans = max(ans, isl);
}
int 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 |
---|
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... |