(B) Petya and Countryside

 avatar
jackoup
c_cpp
8 days ago
985 B
1
Indexable
Never
CodeForces
#include <iostream>
#include <vector>

using namespace std;



int main(){
   int n;cin>>n;
    vector<int> right(n,1) ,left(n,1);
    int arr[n];
    for (int i= 0;i<n;i++ ){
        cin>>arr[i];
    }
        //right section
    for(int i = 0;i<n-1;i++ ) {
        if(arr[i] < arr[i+1]) {
            right[i] = 1;
        }
        else {
            int index = i;
            while(arr[index] >= arr[index +1] && index < n-1) {
                right[i]++;
                index++;
            }
        }
    }
    int mx = 1;
    for(int i = n-1;i>0;i--) {
        if(arr[i]<arr[i-1]) {
            mx = max(left[i]+right[i] ,mx);
        }
        else {
            int index = i;
            while(arr[index] >= arr[index-1] && index >0) {
                left[i]++;
                index--;
            }
            left[i] = left[i] +right[i] - 1;
            mx = max(left[i],mx);
        }
    }
    cout<<mx;

    return 0;
}
Leave a Comment