2014 Mock CCC by Alex and Timothy
Alice's obsession with her friend Bob is so tenacious that she cannot
fall asleep at night. She decided to come up with a plan to secretly
visit Bob in his house while he is sleeping. To not get caught, she must
go only when she knows that Bob will be sound asleep for a while. Alice
knows that people have sleep cycles. Below is an example of a hypnogram,
demonstrating the human sleep cycle.

However, every individual's sleep pattern is different and can be
affected by many different factors. For instance, Bob's sleep cycle can
be different due to his habit of staying up late to watch movies, or due
to him being a heavier sleeper than most. The only thing Alice can truly
rely on is the cold, hard data she has collected from a high-quality
microphone, previously planted outside of Bob's window to monitor his
sleeping patterns.
Given
measurements of Bob's awakeness level
recorded at fixed time intervals, Alice would like to know the length of
the longest dip in the data. A dip is a consecutive sequence of length
three or more that starts at a value, progresses to the minimum value of
the sequence in a strictly decreasing pattern, remains at the minimum
value for one or more iterations, and progresses back up in a strictly
increasing pattern. More specifically, a consecutive subsequence from
to
of a sequence of numbers is a dip if and only if

For example, the sequence
is a dip of
length
, the sequence
is a dip of length
, but the
sequences
,
and
are not
dips. Knowing the length of the longest dip, Alice will then be able to
determine whether she has an opportunity to break in and watch Bob
sleep.
Input Specification
Line
contains the positive integer
, the number of data points to
follow.
Line
contains
positive integers each no greater than
billion,
the measurements of Bob's awakeness levels that Alice has recorded.
Output Specification
One integer - the length of the longest dip, or
if the input does not
contain a dip.
Sample Input
Copy
12
21 5 4 10 8 4 3 6 12 17 4 17
Sample Output
Copy
7
Explanation
The longest dip in the data is
.
Comments