Standing Tall on the Lofty Namsan
InterviewTime limit1sMemory limit512 MB
Given a sequence, decide whether it strictly increases to some peak position and strictly decreases afterward, printing YES or NO.
- Level
Easy3 of 10
- Topics
- Array, Implementation, Greedy
- Solved
- No attempts yet
Problem
Standing tall on the lofty Namsan
(omitted)
Raise up upon the bedrock
The ground of Seonrin
A sequence is a mountain if it increases up to some point and decreases after that point. In other words, there exists a natural number with such that for every with , and for every with .
For example, 1 2 3 4 2 is a mountain because it increases up to the fourth element and decreases after the fourth element (). 1 2 3 4 5 is also a mountain (). However, 1 2 2 3 1 is not a mountain.
Write a program that determines whether a given sequence is a mountain.
Input
The first line gives the length of the sequence, .
The second line gives separated by spaces.
Output
If the given sequence is a mountain, output "YES"; otherwise, output "NO".
Constraints