#include <bits/stdc++.h>
using namespace std;
int main() {
int n, pea = -1, pei, x, sco = 1;
cin >> n;
vector<int> tab(n);
for (int i = 0; i < n; ++i) {
cin >> tab[i];
if (tab[i] > pea) {
pea = tab[i];
pei = i;
}
}
stack<int> uns;
uns.push(pea);
x = pei;
for (int i = 0; i <= n; ++i) {
while (uns.size() && uns.top() <= tab[x])
uns.pop();
uns.push(tab[x]);
sco = max(sco, int(uns.size()));
x--;
if (x < 0) x += n;
}
cout << sco << "\n";
}
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 | #include <bits/stdc++.h> using namespace std; int main() { int n, pea = -1, pei, x, sco = 1; cin >> n; vector<int> tab(n); for (int i = 0; i < n; ++i) { cin >> tab[i]; if (tab[i] > pea) { pea = tab[i]; pei = i; } } stack<int> uns; uns.push(pea); x = pei; for (int i = 0; i <= n; ++i) { while (uns.size() && uns.top() <= tab[x]) uns.pop(); uns.push(tab[x]); sco = max(sco, int(uns.size())); x--; if (x < 0) x += n; } cout << sco << "\n"; } |
English