Description:

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.

Input:

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array.

The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 1 000) — the elements of the

Output:

Print “YES” if the given array is unimodal. Otherwise, print “NO”.

You can output each letter in any case (upper or lower).

Sample Input:

6
1 5 5 5 4 2

Sample Output:

YES

Sample Input:

5
10 20 30 20 10

Sample Output:

YES

Sample Input:

4
1 2 1 2

Sample Output:

NO

Sample Input:

7
3 3 3 3 3 3 3

Sample Output:

YES

题目连接

输入判断标记。

AC代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+5;
const double eps = 1e-5;
const double pi = asin(1.0)*2;
const double e = 2.718281828459;
void fre() {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
}

int n;
int a[maxn];
bool up_flag, flag, down_flag;
bool ans_flag;

int main() {
    up_flag = 0;
    flag = 0;
    down_flag = 0;
    ans_flag = 1;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        if (!ans_flag) {
            continue;
        }
        if (i != 0) {
            if (a[i] == a[i - 1]) {
                if (down_flag) {
                    ans_flag = 0;
                }
                else if (!flag) {
                    flag = 1;
                }
            }
            else {
                if (a[i] > a[i - 1]) {
                    if (flag || down_flag) {
                        ans_flag = 0;
                    }
                    else if (!up_flag) {
                        up_flag = 1;
                    }
                }
                else {
                    if (!down_flag) {
                        down_flag = 1;
                    }
                }
            }
        }
    }
    if (n == 1 || ans_flag) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
    return 0;
}