<PREV Problem:
NEXT>
Solved by 67 users: ...
UserDateAttemptTimeCMSC
kornakovBSU11 dec 2010C++1500.02117 
kornakovBSU11 dec 2010C++1400.02124 
Philip_PV18 oct 2008C900.01131 
Darii11 dec 2010C++900.01131 
Darii10 dec 2010C++600.01136 
Philip_PV18 oct 2008C700.01136 
kornakovBSU11 dec 2010C++1300.01142 
kornakovBSU10 dec 2010C++1200.01162 
stasg708 dec 2008C++200.01166 
david_it2115 dec 2008Ruby400.07168 
svirg01 oct 2008C++200.04175 
Arsuit27 sep 2008C++1200.04179 
JohnJones_00127 sep 2008C400.01180 
WsemirZ24 sep 2008Kylix100.01182 
Darii08 dec 2010C++300.01184 
kornakovBSU07 sep 2010C++600.01191 
Darii08 dec 2010C++200.01195 
N1k1tung29 sep 2008C++300.04199 
Languages
C++
50
C
9
Java
4
Kylix
2
Ruby
1
Python
1
FPC
1
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 

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 190ms

SW soft NIX
ID = 3.229.142.175