.

Pillars

There are n pillars aligned in a row and numbered from 1 to n.

Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai.

You can move these disks from one pillar to another. You can take a disk from pillar i and place it on top of pillar j if all these conditions are met:

there is no other pillar between pillars i and j. Formally, it means that |i−j|=1;
pillar i contains exactly one disk;
either pillar j contains no disks, or the topmost disk on pillar j has radius strictly greater than the radius of the disk you move.
When you place a disk on a pillar that already has some disks on it, you put the new disk on top of previously placed disks, so the new disk will be used to check the third condition if you try to place another disk on the same pillar.

You may take any disk and place it on other pillar any number of times, provided that every time you do it, all three aforementioned conditions are met. Now you wonder, is it possible to place all n disks on the same pillar simultaneously?

Input
The first line contains one integer n (3≤n≤2⋅105) — the number of pillars.

The second line contains n integers a1, a2, …, ai (1≤ai≤n), where ai is the radius of the disk initially placed on the i-th pillar. All numbers ai are distinct.

Output
Print YES if it is possible to place all the disks on the same pillar simultaneously, and NO otherwise. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).

Examples
inputCopy
4
1 3 4 2
outputCopy
YES
inputCopy
3
3 1 2
outputCopy
NO
Note
In the first case it is possible to place all disks on pillar 3 using the following sequence of actions:

take the disk with radius 3 from pillar 2 and place it on top of pillar 3;
take the disk with radius 1 from pillar 1 and place it on top of pillar 2;
take the disk with radius 2 from pillar 4 and place it on top of pillar 3;
take the disk with radius 1 from pillar 2 and place it on top of pillar 3.

**思路:看三个条件,翻译过来就是:找到最大值,从最大值向两侧递减,(每两个相邻的数进行比较)这道题目就解决了,不需要考虑的太复杂

 #include <iostream>
#include <algorithm>

using namespace std;
;
int main()
{
    int x[maxn],i,n;
    cin >> n;
    ;i<n;i++)
        cin >> x[i];
    ;
    ;i<n;i++)
    {
        if(x[m]<x[i])
        {
            m=i;
        }
    }
    ;
    ;i++)
    {
        ])
        {
            flag=;
            break;
        }
    }
    ;i--)
    {
        ]>x[i])
        {
            flag=;
            break;
        }
    }
    ) cout << "NO" <<endl;
    else cout << "YES" <<endl;
    ;
}

CF-----Pillars的更多相关文章

  1. [CF 474E] Pillars (线段树+dp)

    题目链接:http://codeforces.com/contest/474/problem/F 意思是给你两个数n和d,下面给你n座山的高度. 一个人任意选择一座山作为起始点,向右跳,但是只能跳到高 ...

  2. 【CF】474E Pillars

    H的范围是10^15,DP方程很容易想到.但是因为H的范围太大了,而n的范围还算可以接受.因此,对高度排序排重后.使用新的索引建立线段树,使用线段树查询当前高度区间内的最大值,以及该最大值的前趋索引. ...

  3. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  6. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  7. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  8. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  9. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  10. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

随机推荐

  1. CF399B Red and Blue Balls

    题目 CF399B 洛谷RemoteJudge 思路 很容易发现,栈中靠上的蓝色球的出栈,对它下方的蓝色球没有影响. 举个例子: 第一步中靠上的蓝色球在第三步出栈了,这一过程对它下面的蓝色球(即第一步 ...

  2. js-时间相关的转换

    毫秒值 -> 时间 var date = new Date(1477386005*1000);

  3. n皇后(位运算)

    一般解法 算法思路: 对于所有的位置,判断能不能放: 能放就放,处理: 不可行,回溯: 剪枝: 不能在同一行 deep++; 不能在同一列 不能在同一斜线 check k; for(i = 1; i ...

  4. spring自动装配和通过java实现装配

    1.组建扫描 在类上添加注解@Component注解可以实现组建扫描 @Component public class A{ ... } 2.自动装配 通过在属性上或者方法上添加@Autowired注解 ...

  5. C++-HDU1003-Max Sum

    时间复杂度O(n) 空间复杂度O(1) #include <cstdio> int main() { int T;scanf("%d",&T); ,n,a,l, ...

  6. C#学习笔记之泛型

    泛型的作用和约定 提高性能 拆箱和装箱 从值类型转换为引用类型为装箱,把引用类型转换为值类型为拆箱 装箱和拆箱很容易使用,但是性能损失比较大,尤其是遍历许多项的时候. List<T>不使用 ...

  7. DVWA全级别之Brute Force(暴力破解)

    Brute Force Brute Force,即暴力(破解),是指黑客利用密码字典,使用穷举法猜解出用户口令. 首先我们登录DVWA(admin,password),之后我们看网络是否为无代理,: ...

  8. vue 生命钩子周期之理解

    对于vue的初学者来说,理解vue的生命钩子周期是很有必要的.什么是生命钩子周期呢,顾名思义就是 “实例初始化”  到  “实例被销毁” 的过程. 理解vue的生命钩子周期,我们就可以更好的在项目中运 ...

  9. 主席树 hdu 4348

    题意:有一个由n个数组成的序列,有4中操作: 1.C l r d [l,r]这段区间都加上d 2.Q l r 询问[l,r]这段区间的和 3.H l r t 询问之前t时间[l,r]的区间和 4.B ...

  10. Eclipse C++配置静态链接库和动态链接库

    转:https://blog.csdn.net/iteye_20658/article/details/82650699 1.动态库: 一.创建动态链接库1.创建工程new->project-& ...