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

——————————————————————————————————————————

题目的意思是判读啊一个序列是不是先增再平在减的

思路:分类判断

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
#define MAXN 2000010 int a[100005];
int main()
{
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
int flag=0;
int fl=0;
for(int i=1; i<n; i++)
{
if(flag==0)
{
if(a[i]>a[i-1])
continue;
else if(a[i]==a[i-1])
flag=1;
else if(a[i]<a[i-1])
flag=2;
}
else if(flag==1)
{
if(a[i]>a[i-1])
{
fl=1;
break;
}
else if(a[i]==a[i-1])
continue;
else if(a[i]<a[i-1])
flag=2;
}
else if(flag==2)
{
if(a[i]>=a[i-1])
{
fl=1;
break;
}
}
}
printf("%s\n",fl?"NO":"YES");
return 0;
}

Codeforces831A Unimodal Array的更多相关文章

  1. CodeForces - 831A Unimodal Array 模拟

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

  2. Code froces 831 A. Unimodal Array

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

  3. E - Unimodal Array CodeForces - 831A

    Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is cons ...

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

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

  5. 831A- Unimodal Array

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

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

    http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...

  7. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) A 水 B stl C stl D 暴力 E 树状数组

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

  8. CF-831A

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

  9. javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈

    Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...

随机推荐

  1. python+selenium页面自动化 元素定位实际遇到的各种问题(持续更新)

    1.class属性有空格  (已验证) 当classname 中存在空格的时候,直接使用find_element_by_class_name时,会显示定位失败,此时,需要将classname中的空格替 ...

  2. zabbix学习笔记----概念----2019.03.25

    1.zabbix支持的通讯方式 1)agent:专用的代理程序,首推: 2)SNMP:  3)SSH/Telnet:  4)IPMI,通过标准的IPMI硬件接口,监控被监控对象的硬件特性. 2)zab ...

  3. Oracle中number(5,-2)数据类型

    举个例子,1234.345 如果为number(5,-2),那么结果为 1200, 如果为number(5,2),那么结果为 1234.35 如果为number(5),那么结果为 1234 说明: N ...

  4. 关于.idea未上传导致不能显示项目文件结构的问题

    方法一: 关闭IDEA, 然后删除项目文件夹下的.idea文件夹 重新用IDEA工具打开项目 方法二: 菜单:File -> Invalidate Caches / Restart 方法三: 配 ...

  5. CMD运行JAVA出现编码GBK的不可映射字符处理方法?

    方法一: (将notepad编辑器的编码方式改为ANSI后再进行程序代码的编译,将之前乱码的汉字删除重新输入正常的汉字) 1.notepad编辑器默认编码方式为UTF-8时,CMD里面执行javac ...

  6. rabbitmq 启动报错 Failed to get nic info

    这个报错 基本搜索不到什么有效信息 解决办法: hostnamectl set-hostname xxx.local # 先把rabbitmq进程杀掉$ ps -ef | grep rabbitmq ...

  7. .net core中的分布式缓存和负载均衡

    通过减少生成内容所需的工作,缓存可以显著提高应用的性能和可伸缩性,缓存对不经常更改的数据效果最佳,缓存生成的数据副本的返回速度可以比从原始源返回更快.ASP.NET Core 支持多种不同的缓存,最简 ...

  8. crontab学习

    概念 日志路径 /var/log/cron 配置路径 vi /etc/crontab 参考 https://www.cnblogs.com/kenshinobiy/p/7685229.html 问题 ...

  9. VBA读写ini 配置文件

    Option Explicit 'read Private Declare Function GetPrivateProfileString Lib "kernel32" Alia ...

  10. node.js生成二维码

    var http = require('http'); var qs = require('querystring'); var qrImg = require('qr-image'); var se ...