#include<bits/stdc++.h>
using namespace std;
vector<int> tab;
vector<int> stos;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, el, maks = 0, ind, wynik = 0;
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> el;
tab.push_back(el);
if(el > maks)
{
maks = el;
ind = i;
}
}
for(int i = 0; i <= ind; i++)
{
tab.push_back(tab[i]);
}
for(int i = tab.size() - 1; i > ind; i--)
{
el = tab[i];
while(stos.size() && (el >= stos.back()))
{
stos.pop_back();
}
stos.push_back(el);
wynik = max(wynik, (int)stos.size());
}
cout << wynik;
return 0;
}
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 40 41 42 | #include<bits/stdc++.h> using namespace std; vector<int> tab; vector<int> stos; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, el, maks = 0, ind, wynik = 0; cin >> n; for(int i = 0; i < n; i++) { cin >> el; tab.push_back(el); if(el > maks) { maks = el; ind = i; } } for(int i = 0; i <= ind; i++) { tab.push_back(tab[i]); } for(int i = tab.size() - 1; i > ind; i--) { el = tab[i]; while(stos.size() && (el >= stos.back())) { stos.pop_back(); } stos.push_back(el); wynik = max(wynik, (int)stos.size()); } cout << wynik; return 0; } |
English