It's time for Akagi's daily training!
Today, Akagi has set up
Akagi, being an Aircraft Carrier, plans to launch a single plane and attack a location beyond the
Formally, Akagi needs to adjust the heights of the targets such that there exist two targets
It's no problem if any of the targets (including the first) has a negative height — Akagi will simply ask for help from a Submarine Aircraft Carrier. When the deployed plane reaches the peak of the path (target
Completing this training exercise is vital to her performance reviews, so Akagi would like you to figure out the minimal time it takes for her to adjust the targets such that afterwards, there will be a valid flight path that finishes at or beyond the
Constraints
Subtask 1 [40%]
Subtask 2 [60%]
Input Specification
The first line of input will have two integers
The second line of input will have
Output Specification
The first line of output should be the minimal number of nanoseconds it takes Akagi to adjust all the targets for the plane. If it is not possible to adjust the targets in any amount of time, output -1
.
Sample Input
5 4
1 5 2 6 2
Sample Output
8
Explanation for Sample Output
In the optimal solution, the final heights are
Comments