시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB111100.000%

문제

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.

입력

The first line of input contains two integers $N$ and $K$ (with $2≤N≤100$ and $2≤K≤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,\dots ,d_{N-1}$ (with $0≤d_i<2^{31}$) where $d_i$ is the distance between restaurant site $i$ and $i+1$.

출력

Display the number $a-b$.

예제 입력 1

5 3
1 2 3 4

예제 출력 1

0

예제 입력 2

8 4
3 7 3 5 10 4 5

예제 출력 2

2

예제 입력 3

10 5
24 48 26 2 16 32 31 25 50

예제 출력 3

14

힌트

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$.

출처

University > University of Alberta Programming Contest > UAPC 2022 L번

  • 문제를 만든 사람: Noah Weninger