http://acm.sgu.ru/problem.php?contest=0&problem=488
#include<iostream> #include<math.h> using namespace std; int T , N; int a[100000] ={0}; int b[100000] ={0}; int L[100000] ={0}; int R[100000] ={0}; int search(int a[],int n) { int t; for(t = 1 ; t < n; t++) { if(a[t] < a[t-1]) L[t] = L[t -1]; else L[t] = t; } R[n-1] = n-1; for(t =n-1; t> 0; t--) { if(a[t-1] < a[t]) R[t-1] =R[t]; else R[t-1] = t-1; } int ans = 0; for(t =0; t < n; t++) { ans =max(min(t-L[t],R[t]-t),ans); } return ans; } int main() { cin >> T ; //input the number while(T--) { cin >> N; for(int i= 0; i< N;i++) cin>>a[i]; for(int i = 0; i < N; i++) b[i] = -a[i]; cout << search(b, N) << " " << search(a, N) << endl; } return 0; }