#K3781. Longest Bitonic Subarray

    ID: 26059 Type: Default 1000ms 256MiB

Longest Bitonic Subarray

Longest Bitonic Subarray

Given an array of integers, find the length of the longest contiguous subarray that forms a bitonic sequence. A bitonic sequence is defined as a sequence that first strictly increases and then strictly decreases.

Formally, for an array (A) of length (N), define (inc[i]) as the length of the longest strictly increasing contiguous subarray ending at index (i), and (dec[i]) as the length of the longest strictly decreasing contiguous subarray starting at index (i). The answer is (\max_{0 \le i < N} (inc[i] + dec[i] - 1)). If the array is empty, the answer is 0. The solution must read input from standard input and write the output to standard output.

inputFormat

The first line contains an integer (N), the number of elements in the array. The second line contains (N) space-separated integers. When (N = 0), the array is empty.

outputFormat

Output a single integer representing the length of the longest bitonic contiguous subarray.## sample

6
12 4 78 90 45 23
5

</p>