Robotai
InterviewTime limit1sMemory limit1024 MB
Two robots start at both ends of a furrow of length L and plant M trees at given positions. Find the minimum time to plant all of them.
- Level
Medium5 of 10
- Topics
- Binary search, Greedy
- Solved
- No attempts yet
Problem
A straight furrow of length must have trees planted in it. Robots plant the trees, so every distance in the furrow is measured in robopėdos (robot feet).
The positions (distances from the start of the furrow) are . A single tree must be planted at each of these positions.
Two robots do the work. Each robot moves 1 robot foot per 1 time unit, and it takes time units to plant one tree. The first robot starts at position , and the second robot starts at position . Both robots start working at time .
Write a program that finds the minimum time needed to plant all the trees when both robots work.
Input
The first line contains three integers , , and . is the number of positions, is the length of the furrow, and is the time needed to plant one tree.
Each of the next lines contains one integer, the planting positions , given in increasing order.
Output
Print one line with the minimum time .
Constraints