2019.07.23 CFB题

http://codeforces.com/contest/1197/problem/B
B. Pillars
time limit per test1.5 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
int n,a[200005];
int main()
{
	scanf("%d",&n);
	for(int i=0;ia[i-1])
	break;
	if(i==n)
	printf("YES\n");
	else
	printf("NO\n");
}

你可能感兴趣的:(2019.07.23 CFB题)