Go-Kart
InterviewTime limit1sMemory limit1024 MB
Find the smallest fuel-tank capacity that lets a kart refuel at given stations and travel at least K kilometers.
- Level
Medium5 of 10
- Topics
- Binary search, Greedy, Sorting
- Solved
- No attempts yet
Problem
Vytautas got a new go-kart as a Christmas gift and wants to test it on a long, straight karting track.
The kart starts the track with a full fuel tank. It burns one liter of fuel for every kilometer driven and keeps going straight as long as there is fuel in the tank. The tank can be refilled to full at any fuel station.
There are fuel stations on the track; the -th station stands kilometers from the start of the track.
Help Vytautas find the smallest fuel-tank capacity that lets him drive at least kilometers.
Input
The first line contains two positive integers: the number of fuel stations and the distance (in kilometers) that Vytautas wants to drive.
The second line contains positive integers. The -th of them is the distance (in kilometers) of the -th station from the start of the track. The station positions are not necessarily sorted.
Output
Print a single integer: the minimum fuel-tank capacity (in liters) that lets Vytautas drive at least kilometers.
Constraints
- More than one station may stand at the same kilometer.