#include<bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int n;
cin >> n;
vector<int> a(n);
int mx = -1;
int mx_i = -1;
for (int i = 0; i < n; i++) {
int ai;
cin >> ai;
a[i] = ai;
if (ai > mx) {
mx = ai;
mx_i = i;
}
}
int ml = 1;
stack<int> bt;
bt.push(a[mx_i]);
for (int i = (mx_i + n - 1) % n; i != mx_i; i = (i + n - 1) % n) {
while (!bt.empty() && bt.top() <= a[i]) {
bt.pop();
}
bt.push(a[i]);
ml = max(ml, (int) bt.size());
}
cout << ml;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include<bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; cin >> n; vector<int> a(n); int mx = -1; int mx_i = -1; for (int i = 0; i < n; i++) { int ai; cin >> ai; a[i] = ai; if (ai > mx) { mx = ai; mx_i = i; } } int ml = 1; stack<int> bt; bt.push(a[mx_i]); for (int i = (mx_i + n - 1) % n; i != mx_i; i = (i + n - 1) % n) { while (!bt.empty() && bt.top() <= a[i]) { bt.pop(); } bt.push(a[i]); ml = max(ml, (int) bt.size()); } cout << ml; } |
English