题目:Unimodal Array

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

Examples

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

题目大意:

输入样例有多组(隐含意义是输入以文件尾结束,我也是吃过这个的亏,不然就会超时或者其他的错误)
对于每组数据输入一个n表示输入的数据个数
需要对输入的数据进行判断:输入的数据最多有三个部分构成:递增,持平,递减
递增和递减部分可以不存在比如2 2 2 2 2
持平部分可以只有一个数比如1 2 3 2 1
如果符合输出YES否则输出NO。

AC代码:

#include <cstdio>
int a[105];
int main()
{int n;while(~scanf("%d",&n)){for(int i=0;i<n;i++)scanf("%d",&a[i]);int add=1,fair=0,reduce=0;int judge=0;for(int i=0;i<n-1;i++){if(a[i]<a[i+1]){if(fair!=0||reduce!=0){judge=1;break;}}else if(a[i]==a[i+1]){if(reduce!=0){judge=1;break;}if(fair==0)fair=1;}else if(a[i]>a[i+1]){reduce=1;}}if(judge==0)printf("YES\n");elseprintf("NO\n");}return 0;
}

codeforces-831A(Unimodal Array)相关推荐

  1. DirectX12(D3D12)基础教程(二十)—— 纹理数组(Texture Array)非DDS初始化操作

    1.前言 2.纹理(Texture)和纹理数组(Texture Array) 3.纹理数组的创建 4.纹理数组的初始化(两次复制法) 1.前言   在本系列教程的 DirectX12(D3D12)基础 ...

  2. python中数组(numpy.array)的基本操作【转载】

    为什么要用numpy Python中提供了list容器,可以当作数组使用.但列表中的元素可以是任何对象,因此列表中保存的是对象的指针,这样一来,为了保存一个简单的列表[1,2,3].就需要三个指针和三 ...

  3. Dreamoon Likes Coloring CodeForces - 1330C(贪心+思维)

    Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty ( ...

  4. codeforces 762E(cdq分治)

    题意: n个电台,每个电台有三个属性xi, ri, fi.分别代表电台的坐标,电台的播报范围,以及播报的频率. 对于一对电台i, j,若min(ri, rj) >= |xi - xj|,那么他们 ...

  5. Lumerical官方案例、FDTD时域有限差分法仿真学习(七)——纳米孔阵列(Nanohole array)

    我们将计算金属薄膜中纳米孔阵列的透射和反射光谱. 我们还将考虑薄膜表面的近场分布和局部场增强. 一.模拟设置 文件 sp_array.fsp 可用于在 100 nm 厚的金层中模拟半径为 100 nm ...

  6. CodeForces 459C(构造题)

    http://codeforces.com/problemset/problem/459/C /** 题意:有n个同学,k辆车,d天(每天n个同学去一个地方)问经过d天后,任意的多个同学不能总在一起d ...

  7. Longest k-Good Segment CodeForces - 616D(尺取法)

    The array a with n integers is given. Let's call the sequence of one or more consecutive elements in ...

  8. Anu Has a Function CodeForces - 1300C(二进制位运算)

    Anu has created her own function ff: f(x,y)=(x|y)−yf(x,y)=(x|y)−y where || denotes the bitwise OR op ...

  9. Codeforces数据结构(水题)小结

    最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------ ...

  10. JavaScript-数组(new Array)

    创建数组的俩种方式: 1.利用数组字面量 var arr = [1, 2, 3]; console.log(arr); //输出结果为1,2,3 2.利用new Array() var arr1 = ...

最新文章

  1. 【经典书】图论,322页pdf
  2. sicp 4.2.1两题
  3. python调用c++传递数组
  4. Discuz! $_DCACHE数组变量覆盖漏洞
  5. 过来人经验!聊聊前端工程师的职业规划
  6. Node — 第五天
  7. 12-order by和group by 原理和优化 sort by 倒叙
  8. Python内置库修炼——turtle绘图库指令大全
  9. STM32F205时钟配置
  10. 计算机模拟仿真技术的功能,浅谈虚拟仿真技术
  11. Coding and Paper Letter(八十五)
  12. MATLAB三元条件运算符,C++ ?:条件运算符(三目运算符)用法详解
  13. ArcGIS Desktop10.3位置分配,选址分析
  14. Windows Server2008 R2搭建域环境(步骤最详细)
  15. java马斯京根法计算汇流系数P
  16. 小米温湿度计接入homeassistant
  17. Quorum?Quorum!
  18. VSLAM与VIO的3D建图,重定位与世界观综述
  19. 闽高校计算机二级c语言模拟器,闽高校计算机二级C语言模拟卷及答案教案.doc
  20. ffmpeg视频按帧截取图片和ffmpeg将图片合成mp4视频

热门文章

  1. 名字也可能惹祸?Gitee.com被停止域名解析
  2. 百度短网址URL生成
  3. JS逆向-易班登录password参数(RSA加密)
  4. iOS开发各种证书详解
  5. 美通社企业新闻汇总 | 2019.1.16 | 微软与药店巨头沃博联达成战略合作,科勒中国第13家工厂落成...
  6. 苦口婆心一考拉|向沉迷游戏的中(大)学生讲解内存和磁盘
  7. 新人面试时候需要注意的写法
  8. nexus5 android5.0 型号LRX210 ROOT
  9. 计算机怎么知道用户名和密码,电脑的用户名和密码怎么查看
  10. OpenCV:计算三角形的角度