#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
vector<int> v;
deque<int>q;
int main()
{
ios::sync_with_stdio(0);
cin.tie(nullptr);
int n, x;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x;
v.push_back(x);
}
int w = 0;
for (int i = 2*n-1; i >=0; i--)
{
while (!q.empty() and q.front() <= v[i % n])
q.pop_front();
q.push_front(v[i % n]);
w = max(w, (int)q.size());
}
cout << w;
}
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 | #include <iostream> #include <algorithm> #include <string> #include <vector> #include <queue> using namespace std; #define ll long long vector<int> v; deque<int>q; int main() { ios::sync_with_stdio(0); cin.tie(nullptr); int n, x; cin >> n; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } int w = 0; for (int i = 2*n-1; i >=0; i--) { while (!q.empty() and q.front() <= v[i % n]) q.pop_front(); q.push_front(v[i % n]); w = max(w, (int)q.size()); } cout << w; } |
English