#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<long long> a(n);
for (auto &x : a) cin >> x;
if (n == 0) {
cout << "0";
return 0;
}
if (n == 1) {
cout << "1";
return 0;
}
long long gmax=*max_element(a.begin(), a.end());
bool same = true;
for (auto x : a) if (x != a[0]) same = false;
if (same) {
cout << "1\n";
return 0;
}
int ans = 1;
vector<long long> doubled = a;
doubled.insert(doubled.end(), a.begin(), a.end()); // a + a
vector<int> max_records_from(n, 0);
long long current_strict_max = -1;
int count = 0;
for (int i = 2 * n - 1; i >= 0; --i) {
if (i < n) {
}
}
int max_left = 0;
long long mx = -1;
for (int i = 0; i < n; ++i) {
if (a[i] > mx) {
++max_left;
mx = a[i];
}
if (a[i] == gmax) break;
}
ans = max(ans, max_left);
for (int i = 0; i < n; ++i) {
if (a[i] == gmax) {
long long cur = gmax;
int cnt = 1; // sam gmax
for (int j = 1; j < n; ++j) {
int idx = (i + j) % n;
if (a[idx] > cur) {
++cnt;
cur = a[idx];
}
}
ans = max(ans, cnt);
}
}
mx = -1;
int temp = 0;
for (int i = 0; i < n; ++i) {
if (a[i] > mx) {
++temp;
mx = a[i];
}
}
ans = max(ans, temp);
cout << ans;
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<long long> a(n); for (auto &x : a) cin >> x; if (n == 0) { cout << "0"; return 0; } if (n == 1) { cout << "1"; return 0; } long long gmax=*max_element(a.begin(), a.end()); bool same = true; for (auto x : a) if (x != a[0]) same = false; if (same) { cout << "1\n"; return 0; } int ans = 1; vector<long long> doubled = a; doubled.insert(doubled.end(), a.begin(), a.end()); // a + a vector<int> max_records_from(n, 0); long long current_strict_max = -1; int count = 0; for (int i = 2 * n - 1; i >= 0; --i) { if (i < n) { } } int max_left = 0; long long mx = -1; for (int i = 0; i < n; ++i) { if (a[i] > mx) { ++max_left; mx = a[i]; } if (a[i] == gmax) break; } ans = max(ans, max_left); for (int i = 0; i < n; ++i) { if (a[i] == gmax) { long long cur = gmax; int cnt = 1; // sam gmax for (int j = 1; j < n; ++j) { int idx = (i + j) % n; if (a[idx] > cur) { ++cnt; cur = a[idx]; } } ans = max(ans, cnt); } } mx = -1; int temp = 0; for (int i = 0; i < n; ++i) { if (a[i] > mx) { ++temp; mx = a[i]; } } ans = max(ans, temp); cout << ans; return 0; } |
English