Hide

Problem L
Similar Spacing

Finally, your dream of owning a restaurant chain has come true! You have consulted a marketing firm and received instructions on how to best place your restaurants in the city.

The firm has identified potential restaurant sites along a single road, each of which can house a single restaurant. To maximize influencer media impact, you have been advised to build some restaurants along this road and open them all at the same time. Apparently, the best way to attract customers to your chain is to build all of your restaurants with similar spacing along the road; such placement maximizes pedestrian recall coherence, which is all the rage in marketing.

Specifically, if $a$ is the maximum distance between any two adjacent restaurants and $b$ is the minimum distance between any two adjacent restaurants, place your restaurants such that $a-b$ is minimized.

Input

The first line of input contains two integers $N$ and $K$ (with $2 \leq N \leq 100$ and $2 \leq K \leq N$) where $N$ is the number of potential restaurant sites, and $K$ is the number of restaurants to build. The second line of input contains $N-1$ integers $d_1, \ldots , d_{N-1}$ (with $0 \leq d_ i < 2^{31}$) where $d_ i$ is the distance between restaurant site $i$ and $i+1$.

Output

Display the number $a-b$.

Explanation

In Sample Input 2, an optimal solution could place restaurants at sites $1$, $3$, $5$, and $6$. With this placement the distances between adjacent restaurants are $d_1+d_2$, $d_3+d_4$, and $d_5$, respectively. So, $a=10$ (the maximum of these), $b=8$ (the minimum), and $a-b=2$.

In Sample Input 3, an optimal solution could place restaurants at sites $3$, $4$, $6$, $7$, and $8$. With this placement the distances between adjacent restaurants are $d_3$, $d_4+d_5$, $d_6$, and $d_7$, respectively. So, $a=32$, $b=18$, and $a-b=14$.

Sample Input 1 Sample Output 1
5 3
1 2 3 4
0
Sample Input 2 Sample Output 2
8 4
3 7 3 5 10 4 5
2
Sample Input 3 Sample Output 3
10 5
24 48 26 2 16 32 31 25 50
14

Please log in to submit a solution to this problem

Log in