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 array.

Output

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

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

Example

Input
6
1 5 5 5 4 2
Output
YES
Input
5
10 20 30 20 10
Output
YES
Input
4
1 2 1 2
Output
NO
Input
7
3 3 3 3 3 3 3
Output
YES

Note

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).

题解:这是一道判断一组数是是不是单峰的问题,且满足左边严格增加,中间平,最后严格减。

代码为:

#include<iostream>

#include<cstdio>

using namespace std;

#define MAXN 110

int a[MAXN];

int main()

{

    int n;

    while(cin>>n)

    {

        for(int i=1;i<=n;i++)

            cin>>a[i];

       

        int p=2;

        while(a[p]>a[p-1]) p++;

        while(a[p]==a[p-1]) p++;

        while(a[p]<a[p-1]) p++;

        if(p<=n) 
cout<<"NO"<<endl;

        else 
cout<<"YES"<<endl;

    }

    return 0;

}

E - Unimodal Array CodeForces - 831A的更多相关文章

  1. CodeForces - 831A Unimodal Array 模拟

    A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. Codeforces831A Unimodal Array

    A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Code froces 831 A. Unimodal Array

    A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. Greg and Array CodeForces 296C 差分数组

    Greg and Array CodeForces 296C 差分数组 题意 是说有n个数,m种操作,这m种操作就是让一段区间内的数增加或则减少,然后有k种控制,这k种控制是说让m种操作中的一段区域内 ...

  5. 【Codeforces Round #424 (Div. 2) A】Unimodal Array

    [Link]:http://codeforces.com/contest/831/problem/A [Description] 让你判断一个数列是不是这样一个数列: 一开始是严格上升 然后开始全都是 ...

  6. Imbalanced Array CodeForces - 817D (思维+单调栈)

    You are given an array a consisting of n elements. The imbalance value of some subsegment of this ar ...

  7. Petya and Array CodeForces - 1042D (树状数组)

    D. Petya and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. AC日记——Little Elephant and Array codeforces 221d

    221D - Little Elephant and Array 思路: 莫队: 代码: #include <cmath> #include <cstdio> #include ...

  9. Curious Array Codeforces - 407C(高阶差分(?)) || sequence

    https://codeforces.com/problemset/problem/407/C (自用,勿看) 手模一下找一找规律,可以发现,对于一个修改(l,r,k),相当于在[l,r]内各位分别加 ...

随机推荐

  1. idea用hibernate创建一个表两个主键时遇到的问题

    1>> idea功能简单,最大化的实现傻瓜式操作,不需要像eclipse一样手敲代码,尤其是在创建主键多个或者主键映射时. 2>> (1).首先,idea创建复合主键映射时,需 ...

  2. AI的真实感

    目录 1.让AI"不完美"--估算和假设 2 AI感知 全能感知 特定感觉无知 3 AI的个性 4 AI的预判 5 AI的智能等级 ​ AI的真实感一直是游戏AI程序员追求的目标, ...

  3. Electron 菜单切换主题与css替换 ts编写

    ////目标css<link rel="stylesheet" id="theme_css" href="路径"> ////ts ...

  4. Oracle 数据库基础:数据查询与操作

    SELECT uname FROM TUser WHERE uname=‘admin’ SELECT 字段名列表 FROM 表名 WHERE 条件; 在Oracle数据库中,对象是属于模式的,每个账户 ...

  5. JavaScript with Image:创建缩略图

    当图片很大,直接把图片从Server下载到浏览器上看是一种很不明智的做法,浪费了服务器的资源,网络带宽和客户端的资源.所以,通常Server和Client之间会传输缩略图,只有当Client请求某张图 ...

  6. 如何在 PHP 和 Laravel 中使用 Traits

    事实上,PHP 作为一门编程语言存在的问题之一,就是你只能使用单继承.这意味着一个类只能从另一个类中继承.例如,可能希望从几个不同的类继承方法,以防止代码重复.在 PHP 5.4 中 一个新的语言特性 ...

  7. Django 基本使用

    Django 基本使用 Django 安装 pip install django Django 创建项目 django-admin startproject 项目名称 Django 创建应用 pyth ...

  8. nyoj 26-孪生素数问题(打表)

    26-孪生素数问题 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:10 submit:43 题目描述: 写一个程序,找出给出素数范围内的所有孪生素数 ...

  9. 2019CSP day1t2 括号树

    题目背景 本题中合法括号串的定义如下: () 是合法括号串. 如果 A 是合法括号串,则 (A) 是合法括号串. 如果 A,B 是合法括号串,则 AB 是合法括号串. 本题中子串与不同的子串的定义如下 ...

  10. 022.掌握Pod-Pod升级和回滚

    一 deploymentPod升级和回滚 1.1 deployment升级 若Pod是通过Deployment创建的,可以在运行时修改Deployment的Pod定义(spec.template)或镜 ...