#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
void solve() {
int n; cin >> n;
vector<ar<int,2>> a(n);
for (int i = 0; i < n; i++) {
int x; cin >> x;
a[i] = {x, i + 1};
}
sort(a.rbegin(), a.rend()); // sort by decreasing height
int ans = 0, cur = 0;
vector<bool> used(n + 2);
for (int i = 0; i < n; i++) {
used[a[i][1]] = true; cur++;
if (used[a[i][1] - 1]) cur--;
if (used[a[i][1] + 1]) cur--;
if (i == n - 1 || a[i][0] != a[i + 1][0]) ans = max(ans, cur);
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int tc = 1;
// cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
1388 KB |
Output is correct |
2 |
Correct |
22 ms |
1388 KB |
Output is correct |
3 |
Correct |
22 ms |
1388 KB |
Output is correct |
4 |
Correct |
23 ms |
1388 KB |
Output is correct |
5 |
Correct |
22 ms |
1388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
2028 KB |
Output is correct |
2 |
Correct |
17 ms |
1772 KB |
Output is correct |
3 |
Correct |
23 ms |
2156 KB |
Output is correct |
4 |
Correct |
23 ms |
2028 KB |
Output is correct |
5 |
Correct |
22 ms |
2028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
249 ms |
17644 KB |
Output is correct |
2 |
Correct |
253 ms |
17644 KB |
Output is correct |
3 |
Correct |
262 ms |
17772 KB |
Output is correct |
4 |
Correct |
251 ms |
17772 KB |
Output is correct |
5 |
Correct |
246 ms |
17004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
254 ms |
17004 KB |
Output is correct |
2 |
Correct |
255 ms |
17004 KB |
Output is correct |
3 |
Correct |
254 ms |
17004 KB |
Output is correct |
4 |
Correct |
234 ms |
11244 KB |
Output is correct |
5 |
Correct |
234 ms |
11168 KB |
Output is correct |