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
#include<bits/stdc++.h>
using namespace std;

typedef pair<int, int> par;
deque<par> de;
int tab[1000009];

int main()
{
    int n, a, wyn;
    cin>>n;
    for(int i=1; i<=n; i++) {
		cin>>tab[i];
		if(de.size() == 0 || tab[i] > de.back().first) de.push_back({tab[i], i});
	}
	wyn = de.size();
	for(int i=n; i>=2; i--) {
		if(de.size() > 0 && de.back().second == i) de.pop_back();
		while(de.size() > 0 && tab[i] >= de.front().first) de.pop_front();
		de.push_front({tab[i], i});
		if(wyn < de.size()) wyn = de.size();
	}
	cout<<wyn;
    return 0;
}