#include <algorithm>
#include <memory>
#include <vector>
int A[1000000];
int main()
{
int N; scanf("%d", &N);
for (int n=0; n<N; ++n) scanf("%d", &A[N-1-n]);
int max_index = std::max_element(A, A+N) - A;
std::vector<int> zebrane; // liczby, malejąco
zebrane.reserve(N);
int max_length = 0;
for (int n0=0; n0<N; ++n0) {
int n = (n0 + max_index) % N;
auto it = std::lower_bound(zebrane.begin(), zebrane.end(), A[n], std::greater<int>());
if (it != zebrane.end()) {
zebrane.resize(it - zebrane.begin());
}
zebrane.push_back(A[n]);
max_length = std::max<int>(max_length, zebrane.size());
}
printf("%d\n", max_length);
}
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 | #include <algorithm> #include <memory> #include <vector> int A[1000000]; int main() { int N; scanf("%d", &N); for (int n=0; n<N; ++n) scanf("%d", &A[N-1-n]); int max_index = std::max_element(A, A+N) - A; std::vector<int> zebrane; // liczby, malejąco zebrane.reserve(N); int max_length = 0; for (int n0=0; n0<N; ++n0) { int n = (n0 + max_index) % N; auto it = std::lower_bound(zebrane.begin(), zebrane.end(), A[n], std::greater<int>()); if (it != zebrane.end()) { zebrane.resize(it - zebrane.begin()); } zebrane.push_back(A[n]); max_length = std::max<int>(max_length, zebrane.size()); } printf("%d\n", max_length); } |
English