Unimodal Array

题意翻译

## 题目描述 一个整数数组是单峰的,如果: 一开始它是严格增加的; 之后是恒定不变的; 再后是严格减少的; 第一块(增加)和最后一块(减少)可能不存在。允许这两块都不存在。 例如,下面这三个数组是单峰的: $[5,7,11,11,2,1] , [4,4,2] , [7]$ 但是,下面这三个不是单峰的: $[5,5,6,6,1] , [1,2,1,2] , [4,5,5,6]$ 写一个程序来判断一个数组是否是单峰的。 ### 输入格式: 第一行包含一个整数 $n$ ($1\leq n\leq 100$ ) — 这个数组中元素的个数。 第二行包含$n$ 个整数$a_1,a_2,\dots,a_n$ ($1\leq a_i\leq 1000$ ) — 数组中的元素。 ### 输出格式: 如果,被给出的这个元素是单峰的,输出"YES",否则输出"NO"。 在任何情况,你都能输出每个字母(上面的或下面的)。 ### 说明 第一个样例中的数组是单峰的,因为它是在开始的时候严格递增(从位置$1$ 到位置$2$ ,含端点),中间恒定不变(从位置$2$ 到位置$4$ ,含端点)并在最后严格递减(从位置$4$ 到位置$6$ ,含端点)。 by @Khassar

题目描述

Array of integers is unimodal, if: - it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: $ [5,7,11,11,2,1] $ , $ [4,4,2] $ , $ [7] $ , but the following three are not unimodal: $ [5,5,6,6,1] $ , $ [1,2,1,2] $ , $ [4,5,5,6] $ . Write a program that checks if an array is unimodal.

输入输出格式

输入格式


The first line contains integer $ n $ ( $ 1<=n<=100 $ ) — the number of elements in the array. The second line contains $ n $ integers $ a_{1},a_{2},...,a_{n} $ ( $ 1<=a_{i}<=1000 $ ) — the elements of the array.

输出格式


Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower).

输入输出样例

输入样例 #1

6
1 5 5 5 4 2

输出样例 #1

YES

输入样例 #2

5
10 20 30 20 10

输出样例 #2

YES

输入样例 #3

4
1 2 1 2

输出样例 #3

NO

输入样例 #4

7
3 3 3 3 3 3 3

输出样例 #4

YES

说明

In the first example the array is unimodal, because it is strictly increasing in the beginning (from position $ 1 $ to position $ 2 $ , inclusively), that it is constant (from position $ 2 $ to position $ 4 $ , inclusively) and then it is strictly decreasing (from position $ 4 $ to position $ 6 $ , inclusively).