Brian the Computer Science Nerd is going on a date with his girlfriend,
Anatevka! His romantic location of choice is a Chinese restaurant.
At this restaurant,
different dishes are
available, and Brian would like to order each one exactly once. The
waiter will come to his table to take orders
times - the
-th time
he comes will be
minutes after the start of the meal. He has quite a poor
memory, so each time he comes by, Brian will have a chance to order
exactly one new dish.
Dish
takes
minutes to prepare,
which means that it will generally come exactly that many minutes after
being ordered, delivered by a different waiter who will not take orders.
However, meals are guaranteed to arrive in the same order in which they
were ordered - this means that, if meal
was ordered before meal
,
but meal
is ready before meal
, then meal
will instead arrive
at the same time as meal
.
Now, Brian considers time spent waiting for the first meal after the
start of the dinner, as well as for each subsequent meal after the
previous one, to be idle time. Of course, these are the worst parts of
the date, as they require actually engaging in conversation rather than
consuming sustenance. In order to impress Anatevka with his optimal
ordering skills, he'd like to minimize the length of the largest
continuous stretch of idle time throughout the dinner.
Input Specification
Line
:
integer, 
Line
:
integers, 
Line
:
integers, 
Output Specification
integer, the minimal length possible for the longest stretch of idle
time throughout the meal, in minutes.
Sample Input
Copy
3
1 5 6
4 2 3
Sample Output
Copy
4
Explanation of Sample
Brian's optimal strategy is to order dish
, then
, then
. These
dishes will then arrive
,
, and
minutes into the dinner,
respectively. The longest stretch of idle time is then
minutes long.
As a further example, if Brian were to order dish
, then
, then
, the
last
dishes would both arrive
minutes into the dinner, with dish
being held up by dish
.
Comments