#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#include <numeric>
#include <deque>
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int n;
std::cin >> n;
std::vector<int> perly(n);
for (int i = 0; i < n; ++i)
{
int perla;
std::cin >> perla;
perly[i] = perla;
}
int max = 0;
std::deque<int> piekne;
for (int i = 0; i < n; ++i)
{
if (perly[i] > max)
{
piekne.push_back(perly[i]);
max = perly[i];
}
}
int maxPieknych = piekne.size();
for (int i = n - 1; i >= 0; --i)
{
int perla = perly[i];
while (piekne.size() > 0 && piekne.front() <= perla)
{
piekne.pop_front();
}
piekne.push_front(perla);
maxPieknych = std::max((int)piekne.size(), maxPieknych);
}
std::cout << maxPieknych << "\n";
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 | #include <iostream> #include <vector> #include <set> #include <algorithm> #include <cmath> #include <unordered_set> #include <unordered_map> #include <cassert> #include <numeric> #include <deque> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; std::cin >> n; std::vector<int> perly(n); for (int i = 0; i < n; ++i) { int perla; std::cin >> perla; perly[i] = perla; } int max = 0; std::deque<int> piekne; for (int i = 0; i < n; ++i) { if (perly[i] > max) { piekne.push_back(perly[i]); max = perly[i]; } } int maxPieknych = piekne.size(); for (int i = n - 1; i >= 0; --i) { int perla = perly[i]; while (piekne.size() > 0 && piekne.front() <= perla) { piekne.pop_front(); } piekne.push_front(perla); maxPieknych = std::max((int)piekne.size(), maxPieknych); } std::cout << maxPieknych << "\n"; return 0; } |
English