|Online MIPT programming contest||РУССКИЙ|
Time limit = 2 second(s)
Memory limit = 64 MbThe 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.
3 1 1 1
4 5 6 5 4
5 1 -2 -5 3 0
YES -5 3
Artem Voroztsov, individual MIPT contest, 21 sep., 2008
20 September 2008
© acm.mipt DevGroup
The page was generated in 170ms