#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define st first
#define nd second
void solve() {
int n; cin >> n;
vector<int> a(n), b(n);
int maxidx = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > a[maxidx]) maxidx = i;
}
for (int i = maxidx+1; i < n; i++) b[i-maxidx-1] = a[i];
for (int i = 0; i <= maxidx; i++) b[i+n-(maxidx+1)] = a[i];
// for (int i = 0; i < n; i++) cout << b[i] << ' ';
vector<int> dec = {(int)1e9};
int ans = 0;
for (int i = n-1; i >= 0; i--) {
while (dec.back() <= b[i]) dec.pop_back();
dec.push_back(b[i]);
ans = max(ans, (int)dec.size()-1);
}
cout << ans << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
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; typedef long long ll; typedef long double ld; #define st first #define nd second void solve() { int n; cin >> n; vector<int> a(n), b(n); int maxidx = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > a[maxidx]) maxidx = i; } for (int i = maxidx+1; i < n; i++) b[i-maxidx-1] = a[i]; for (int i = 0; i <= maxidx; i++) b[i+n-(maxidx+1)] = a[i]; // for (int i = 0; i < n; i++) cout << b[i] << ' '; vector<int> dec = {(int)1e9}; int ans = 0; for (int i = n-1; i >= 0; i--) { while (dec.back() <= b[i]) dec.pop_back(); dec.push_back(b[i]); ans = max(ans, (int)dec.size()-1); } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } } |
English