시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 256 MB 254 79 63 36.000%

문제

수열이 주어졌을 때, M을 수열의 모든 두 원소의 차이 중 가장 큰 값이라고 한다. m은 그 차이 중 가장 작은 값이라고 한다.

크기가 N인 수열 V가 주어진다. 여기서 K개 수를 적절히 제거해서 M+m을 가능한 작게 만드는 프로그램을 작성하시오.

입력

첫째 줄에 N(3 ≤ N ≤ 1,000,000)과 K(1 ≤ K ≤ N-2)가 주어진다.

둘째 줄에 V의 원소가 공백으로 구분되어 주어진다. (-5,000,000 ≤ Vi ≤ 5,000,000)

출력

첫째 줄에 가장 작은 M+m을 출력한다.

예제 입력 1

5 2
-3 -2 3 8 6

예제 출력 1

7
W3sicHJvYmxlbV9pZCI6IjM5ODgiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMyMTggXHVhY2UwXHViOTc0XHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD5cdWMyMThcdWM1ZjRcdWM3NzQgXHVjOGZjXHVjNWI0XHVjODRjXHVjNzQ0IFx1YjU0YywgTVx1Yzc0NCBcdWMyMThcdWM1ZjRcdWM3NTggXHViYWE4XHViNGUwIFx1YjQ1MCBcdWM2ZDBcdWMxOGNcdWM3NTggXHVjYzI4XHVjNzc0IFx1YzkxMSBcdWFjMDBcdWM3YTUgXHVkMDcwIFx1YWMxMlx1Yzc3NFx1Yjc3Y1x1YWNlMCBcdWQ1NWNcdWIyZTQuIG1cdWM3NDAgXHVhZGY4IFx1Y2MyOFx1Yzc3NCBcdWM5MTEgXHVhYzAwXHVjN2E1IFx1Yzc5MVx1Yzc0MCBcdWFjMTJcdWM3NzRcdWI3N2NcdWFjZTAgXHVkNTVjXHViMmU0LjxcL3A+XHJcblxyXG48cD5cdWQwNmNcdWFlMzBcdWFjMDAgTlx1Yzc3OCBcdWMyMThcdWM1ZjQgVlx1YWMwMCBcdWM4ZmNcdWM1YjRcdWM5YzRcdWIyZTQuIFx1YzVlY1x1YW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UgZmlyc3QgYW5kIG9ubHkgbGluZSBvZiBvdXRwdXQgbXVzdCBjb250YWluIHRoZSBzbWFsbGVzdCBwb3NzaWJsZSBzdW0gTSArIG0uJm5ic3A7PFwvcD5cclxuXHJcbjxwPiZuYnNwOzxcL3A+XHJcbiIsImhpbnQiOiIiLCJvcmlnaW5hbCI6IjEiLCJwcm9ibGVtX2xhbmdfY29kZSI6Ilx1YzYwMVx1YzViNCJ9XQ==

출처

Contest > Croatian Open Competition in Informatics > COCI 2012/2013 > Contest #4 4번

  • 문제를 번역한 사람: baekjoon
  • 데이터를 추가한 사람: rdd6584