406438: GYM102409 J Best division

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Best divisiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Diego is out with $$$3$$$ of his friends (Jorge, Juan and Bob), when out of nowhere one of them realizes that there is a gigantic bar or chocolate, every single one of them is greedy so they want to eat as much chocolate as possible.

After many hours of arguing who gets to eat the most chocolate they came up with the following: the best division is one such that the difference between the person who eats the most chocolate and the person who eats the least chocolate is as small as possible.

As they are about to begin distributing the chocolate bar they came up to a realization, this bar has the shape of a rectangle, has exactly length $$$L$$$ and also has exactly $$$N-1$$$ different cutting spots, each spot located at a specific position $$$x_i$$$ (assuming that the chocolate bar begins in position $$$0$$$). So they must cut the chocolate bar in exactly $$$3$$$ of the cutting spots.

Help Diego find out the optimal way of dividing the chocolate bar in $$$4$$$ such that the difference between whoever eats less and whoever eats most is minimal.

Input

A line with 2 integers, $$$N, L$$$ $$$(4 \le N \le 10^5, 4 \le L \le 10^{15})$$$, the amount of cutting spots within the chocolate bar and the length of the chocolate bar.

Followed by a line with $$$N-1$$$ integers in increasing order, representing the position of the ith cutting spot $$$(1 \le x_i < 10^{15})$$$. It's guaranteed that $$$x_i < x_{i+1}$$$ for $$$1 \le i < N - 1$$$.

Output

A single integer $$$M$$$, the minimal delta between the smallest and biggest piece of chocolate if we divide the bar into exactly $$$4$$$ pieces.

ExampleInput
8 18
3 4 5 8 10 12 15
Output
2
Note

In the test case, given the positions it's the equivalent of saying that we have 8 pieces of the following lengths: 3 1 1 3 2 2 3 3 There are 2 optimal answers, we can either split it in such a way that the 4 chocolate pieces the friends are going to eat are of sizes 5 5 5 3, or of sizes 4 4 4 6.

Source/Category

加入题单

算法标签: