아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Similar Spacing

시간 제한2초메모리 제한1024 MB

요약
직선 위 N개 지점 중 K개를 골라 인접한 선택 지점 사이 간격의 최댓값과 최솟값의 차이를 최소로 만든다.
난이도

보통10점 중 7점

유형
이분 탐색, 슬라이딩 윈도우, 그리디
정답자
아직 제출이 없습니다

문제

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 aa is the maximum distance between any two adjacent restaurants and bb is the minimum distance between any two adjacent restaurants, place your restaurants such that a−ba-b is minimized.

입력

The first line of input contains two integers NN and KK (with 2≤N≤1002≤N≤100 and 2≤K≤N2≤K≤N) where NN is the number of potential restaurant sites, and KK is the number of restaurants to build. The second line of input contains N−1N-1 integers d_1,…,d_N−1d\_1,\dots ,d\_{N-1} (with 0≤d_i<2310≤d\_i<2^{31}) where d_id\_i is the distance between restaurant site ii and i+1i+1.

출력

Display the number a−ba-b.

힌트

In Sample Input 2, an optimal solution could place restaurants at sites 11, 33, 55, and 66. With this placement the distances between adjacent restaurants are d_1+d_2d\_1+d\_2, d_3+d_4d\_3+d\_4, and d_5d\_5, respectively. So, a=10a=10 (the maximum of these), b=8b=8 (the minimum), and a−b=2a-b=2.

In Sample Input 3, an optimal solution could place restaurants at sites 33, 44, 66, 77, and 88. With this placement the distances between adjacent restaurants are d_3d\_3, d_4+d_5d\_4+d\_5, d_6d\_6, and d_7d\_7, respectively. So, a=32a=32, b=18b=18, and a−b=14a-b=14.

예제3

  1. 예제 1

    입력
    5 3
    1 2 3 4
    
    예상 출력
    0
    
  2. 예제 2

    입력
    8 4
    3 7 3 5 10 4 5
    
    예상 출력
    2
    
  3. 예제 3

    입력
    10 5
    24 48 26 2 16 32 31 25 50
    
    예상 출력
    14