<PREV Problem:
NEXT>
Solved by 67 users: ...
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 

Fading sequence

Time limit = 2 second(s)

Memory limit = 64 Mb

The physics professor needs a program which detects whether a sequence of numbers describes fading oscillations for the analysis of experimental data.

After long arguing you got the definition of a fading oscillations.

A local maximum is one or more consequent elements with smaller elements both to the left and to the right. Local minimum is defined analogously. According to this definition, the first and the last values in the sequence are not considered to be a minimum or a maximum.

A sequence is called "fading oscillations" if it has got at least one local minimum and one local maximum and, moreover, the tail of the sequence lies in [min, max] where min and max are the values of the last (before the tail) local minimum and local maximum (the last condition is to be applied only after the first minimum and maximum are reached).

You failed to assure the prof that the definition looks like describing a sequence of non-increasing oscillations. Well, the customer is always right.

Input The first line contains the length of the sequence N, 0 < N < 100000. A sequence of integers from [-108, 108], delimited by spaces, follows.

Output Print YES and the last values of min and max if the sequence is fading oscillations and NO otherwise.

Input#1
3
1 1 1
Output#1
NO
Input#2
4
5 6 5 4 
Output#2
NO
Input#3
5
1 -2 -5 3 0
Output#3
YES
-5 3

Author:
Artem Voroztsov, individual MIPT contest, 21 sep., 2008
20 September 2008

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 200ms

SW soft NIX
ID = 54.144.21.195