Round #424 A. 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

61 5 5 5 4 2

output

YES

input

510 20 30 20 10

output

YES

input

41 2 1 2

output

NO

input

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

 1 /*
 2 题目大意:有一个序列
 3 如果满足左部严格上升(可以为空),中间恒定,右部严格下降(可以为空)
 4 那么就输出YES,否则输出NO
 5 解题思路:按照规则走一遍,如果没走完,那么就NO,否则YES。
 6 */
 7 #include <iostream>
 8 using namespace std;
 9 const int MAXN=105;
10 const int INF=0x3f3f3f3f;
11 int a[MAXN];
12 int main(){
13     int n;
14     while(cin>>n){
15         for(int i=1;i<=n;i++)
16             cin>>a[i];
17         a[n+1]=INF;
18         int p=2;
19         while(a[p]>a[p-1]) p++;
20         while(a [p]==a[p-1]) p++;
21         while(a[p]<a[p-1])  p++;
22         if(p<=n) cout<<"NO"<<endl;
23         else cout<<"YES"<<endl;
24     }
25     return 0;
26 }
 1 #include <iostream>
 2 #define N 105
 3 using namespace std;
 4 int n,maxn=1,a[N];
 5 bool check(){
 6     for(int i=1;i<=n;i++){
 7         if(a[i]==maxn){
 8             for(int j=i-1;j>=1;j--)
 9                 if(a[j]>=a[j+1]) return false;
10             while(a[i]==maxn&&i<=n)
11                 i++;
12             for(int j=i;j<=n;j++)
13                 if(a[j-1]<=a[j]||a[j]>=maxn)
14                 return false;
15             break;
16         }
17     }
18     return true;
19 }
20 int main(){
21     cin>>n;
22     for(int i=1;i<=n;i++)
23         cin>>a[i],maxn=max(a[i],maxn);
24     if(check())
25         cout<<"YES"<<endl;
26     else cout<<"NO"<<endl;
27     return 0;
28 }
时间: 2024-10-17 21:43:17

Round #424 A. Unimodal Array的相关文章

Codeforces Round #424 (Div. 2) A-C

A. Unimodal Array 水题 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <iomanip> #include <math.h> #include <map> using namespace

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

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

D题fst了,生无可恋.第二场rated的CF,打得精神恍惚 A. Unimodal Array 题意:判断数列是否是单峰的. 像题意那样分为三个阶段随便判一判就好了 #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; int n,x[105],part=1; bool f=1; int main() { scanf(&quo

Educational Codeforces Round 23 D. Imbalanced Array(单调栈)

题目链接:Educational Codeforces Round 23 D. Imbalanced Array 题意: 给你n个数,定义一个区间的不平衡因子为该区间最大值-最小值. 然后问你这n个数所有的区间的不平衡因子和 题解: 对每一个数算贡献,a[i]的贡献为 当a[i]为最大值时的 a[i]*(i-l+1)*(r-i+1) - 当a[i]为最小值时的a[i]*(i-l+1)*(r-i+1). 计算a[i]的l和r时,用单调栈维护.具体看代码,模拟一下就知道了. 然后把所有的贡献加起来.

Codeforces Round #424 (Div. 2) E. Cards Sorting(线段树)

题目链接:Codeforces Round #424 (Div. 2) E. Cards Sorting 题意: 将n个数放进一个队列,每次检查队首,看看是不是队列中最小的数,如果是就扔掉,如果不是就放到队尾. 这样直到队列为空,为需要操作多少次. 题解: 考虑用两个指针模拟,最开始now指针指向第一个数,然后nxt指针指向下一个将要被删除的数. 然后我们要算出这里需要移动多少步,然后删掉这个数,一直重复操作,直到将全部的数删完. nxt指针可以用set来维护,now指针可以用并查集来维护. 计

Codeforces Round #424 (Div. 2) D 思维 E set应用,树状数组

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) D. Office Keys 题意:一条直线上,有个办公室坐标 p,有 n个人在a[i],有 k把钥匙在b[i],每个人必须拿到一把钥匙,然后到办公室.问怎么安排花的时间最短. tags:还是不懂套路啊..其实多画两下图就能够感觉出来,2333 关键是要看出来,n个人拿的 n把钥匙应该是连续的. 然后,就是瞎暴力.. #include<bits/stdc++.h> usi

CodeForces 831A 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 thi

Educational Codeforces Round 63 D. Beautiful Array

D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers. Beauty of array is the maximum sum of some consecutive subarray of t