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

直接按题意进行判断

#include<stdio.h>
bool flag;
bool flag1;
bool flag2;
int main()
{
int n;
int a[105];
while (~scanf("%d", &n))
{
flag = true;
flag1 = true;
flag2 = true;
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
if (n == 1)
{
printf("YES\n");
continue;
}
for (int i = 1; i < n; i++)
{
if (a[i] == a[i - 1]&&flag1 )
{
flag = false;
}
else if (a[i]<a[i - 1])
{
flag = false;
flag1 = false;
}
else if (a[i] > a[i - 1] && (!flag||!flag1))
{
flag2 = false;
break;
}
else if (a[i] == a[i - 1] &&!flag1)
{
flag2 = false;
}
}
if (!flag2)
{
printf("NO\n");
}
else
{
printf("YES\n");
}
}
return 0;
}

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

  1. Codeforces 371A K-Periodic Array(模拟)

    题目链接 K-Periodic Array 简单题,直接模拟即可. #include <bits/stdc++.h> using namespace std; #define REP(i, ...

  2. Codeforces 482B Interesting Array(线段树)

    题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...

  3. Codeforces831A Unimodal Array

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

  4. Codeforces 1077C Good Array 坑 C

    Codeforces 1077C Good Array https://vjudge.net/problem/CodeForces-1077C 题目: Let's call an array good ...

  5. codeforces 482B. Interesting Array【线段树区间更新】

    题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...

  6. codeforces 407C Curious Array

    codeforces 407C Curious Array UPD: 我觉得这个做法比较好理解啊 参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377 ...

  7. codeforces 797 E. Array Queries【dp,暴力】

    题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...

  8. Code froces 831 A. Unimodal Array

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

  9. E - Unimodal Array CodeForces - 831A

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

随机推荐

  1. javascript 高度相关

    //scrollTop; var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop); ...

  2. 20155303 2016-2017-2 《Java程序设计》第七周学习总结

    20155303 2016-2017-2 <Java程序设计>第七周学习总结 教材学习中的问题和解决过程 『问题一』:SimpleDateFormat中每个字符的含义都是什么? 『问题一解 ...

  3. 20155330 2016-2017-2 《Java程序设计》第五周学习总结

    20155330 2016-2017-2 <Java程序设计>第五周学习总结 教材学习内容总结 学习目标 理解异常架构 掌握try...catch...finally处理异常的方法 会用t ...

  4. Request爬取网站(seo.chinaz.com)百度权重的查询结果

    一:脚本需求 利用Python3查询网站权重并自动存储在本地数据库(Mysql数据库)中,同时导出一份网站权重查询结果的EXCEL表格 数据库类型:MySql 数据库表单名称:website_weig ...

  5. Ubuntu: HDF5报错: HDF5 header version与HDF5 library不匹配

    今天在执行一个用到hdf5的python脚本时,遇到如下错误 Warning! ***HDF5 library version mismatched error*** The HDF5 header ...

  6. 【译】第八篇 Integration Services:高级工作流管理

    本篇文章是Integration Services系列的第八篇,详细内容请参考原文. 简介在前面两篇文章,我们创建了一个新的SSIS包,学习了SSIS中的脚本任务和优先约束,并检查包的MaxConcu ...

  7. mybatis的配置文件中<selectKey>标签问题

    1.mybatis的配置文件中,使用sequence生成主键 未执行add方法之前,主键未生成(null):刚执行add之后,主键即生成(212) 这里的重点是,一旦执行add方法,配置文件中的sel ...

  8. 通过BurpSuite和sqlmap配合对dvwa进行sql注入测试和用户名密码暴力破解

    0x1 工具和环境介绍 dvwa:渗透测试环境 BurpSuite:强大的WEB安全测试工具 sqlmap:强大的sql注入工具 以上工具和环境都在kali linux上安装和配置. 0x2 步骤说明 ...

  9. Strusts2笔记8--文件的上传和下载

    文件的和上传和下载: (1)文件的上传: Struts是通过拦截器实现文件上传的,而默认拦截器栈中包含了文件上传拦截器,故表单通过Struts2可直接将文件上传,其底层是通过apache的common ...

  10. Ubuntu使用apt-get upgrade升级时出错

    今天在按照常规的sudo apt-get update更新软件列表后,再使用sudo apt-get upgrade升级软件时,出现了以下的错误: 正在设置 linux-image-extra-4.4 ...