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. [Solution] 893. Groups of Special-Equivalent Strings

    Difficulty: Easy Problem You are given an array A of strings. Two strings S and T are special-equiva ...

  2. pwnable.kr-col-witeup

    和上道题类似,先看看col.c代码呗. 欧克,此程序可以查看flag内容,下载下来慢慢分析. 好叭,他是要输入20个字节,然后每4个字节分块这样相加,结果和0x21DD09EC比较. 先验尝试可知,不 ...

  3. CentOS7 安装并配置MySQL8.0

    安装环境 linux版本:CentOS 7.6 x64 Mysql:8.0 在CentOS中默认安装有MariaDB,但是我们需要的是MySQL,安装MySQL可以覆盖MariaDB. MariaDB ...

  4. django xadmin后台页面实现二级联动

    思路 先找到控件id ,这样就可以监听change事件 然后把自己写的js加入xadmin中 添加url和view,接受ajax请求和发送数据 第一步:找到联动上下级的ID 在浏览器中通过F12查看 ...

  5. hive上传数据到oracle

    # Oracle 建立hive外部表 使用oracle的大数据连接器向建立hive的外部表,在通过在oracle中根据外部表建立内部表(create table as select * from ex ...

  6. js千分位加逗号

    code function toThousands(num) { var numArr = num.split('.'); num = numArr[0]; var result = ''; whil ...

  7. .NET Core PartialView 与 Ajax

    Ajax的核心是XMLHttpRequest对象(XHR),能够以异步方式从服务器获取新数据.开发主要利用Ajax来执行异步刷新和局部视图更新的功能. 而开发常常在前段页面利用JQuery封装的Aja ...

  8. Jenkins+docker自动部署

    项目目录结构如下 对此项目,使用Jenkins构建dockers镜像 步骤如下: 1.安装Jenkins和docker,具体安装步骤,自行度娘把,在此不详述了. 2.Jenkins安装插件Gradle ...

  9. Python爬虫——Request模块

    # 使用 Requests 发送网络请求# 1.导入 Requests 模块import requests# 2.尝试获取某个网页 # HTTP 请求类型r = requests.get('https ...

  10. MVC htmlAttributes and additionalViewData

    @Html.TextBoxFor(m => m.UserName, new { title = "ABC" }) // 输出结果为 <input data-val=&q ...