A. Unimodal Array
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

这一题读完之后我就顺着题意列出成立的5种情况,把数据做成线状图的话是:

1.先增后平

2.先增后减

3.先增后平后减

4.先平后减

5.一直平

然而这样实现的话太麻烦了,代码我都不好意思贴出来。

看了cf上高手的代码,一目了然。

 1 #include <cstdio>
2 const int M = 1111;
3 int nu[M];
4 int main(){
5 int n,f=0;
6 scanf("%d",&n);
7 for(int i=0;i<n;i++){
8 scanf("%d",&nu[i]);
9 }
10 while(nu[f]<nu[f+1]&&f<n-1) f++;
11 while(nu[f]==nu[f+1]&&f<n-1) f++;
12 while(nu[f]>nu[f+1]&&f<n-1) f++;
13 if(f==n-1) puts("YES");
14 else puts("NO");
15 return 0;
16 }

最新文章

  1. Android源码中内置包含so文件的APK文件
  2. SQL Server中的事务日志管理(7/9):处理日志过度增长
  3. 你所不知道的Android Studio调试技巧
  4. JavaIDL开发CORBA实例演示
  5. codeforces MUH and Cube Walls
  6. Apache Commons CLI 简介
  7. strcpy/strlen/strcat/strcmp面试总结
  8. 你跟上技术趋势了么? 来看看这10场2017热门it技术会议!
  9. 使用递归算法结合数据库解析成java树形结构
  10. Android ListView Adapter的getItemViewType和getViewTypeCount多种布局
  11. HDU2689-Sort it-冒泡排序
  12. 深入理解C#中的IDisposable接口
  13. mysql 开发进阶篇系列 9 锁问题 (Innodb 行锁实现方式)
  14. [20171113]修改表结构删除列相关问题4.txt
  15. BZOJ4033或洛谷3177 [HAOI2015]树上染色
  16. [Vuejs] 组件 v-if 和 v-show 切换时生命周期钩子的执行
  17. Linux 安装Python虚拟环境,virtualenvwrapper
  18. hdu 2795 公告板 (单点最值)
  19. 一起学习Maven
  20. 转载:mysql数据同步redis

热门文章

  1. Python3.9的http.client.py下的HTTPMessage类中的方法getallmatchingheaders的bug修复建议
  2. PAT Advanced 1004 Counting Leaves
  3. Java并发包源码学习系列:阻塞队列BlockingQueue及实现原理分析
  4. QQ好友状态,QQ群友状态,究竟是推还是拉? 网页端收消息,究竟是推还是拉?
  5. 后台故障&amp;性能分析常用工具
  6. LOJ10131暗的连锁
  7. Excel常见后缀名
  8. H5Slides幻灯演示系统
  9. JDBC连接Oracle实现增、删、改操作
  10. Tomcat优化,JNDI,连接池,数据源