diff --git a/pknujsp/README.md b/pknujsp/README.md index a5585860..39896530 100644 --- a/pknujsp/README.md +++ b/pknujsp/README.md @@ -40,4 +40,5 @@ | 36차시 | 2024.02.21 | 이진탐색 | [휴게소 세우기](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143) | | 37차시 | 2024.03.04 | 구현 | [n+1 카드게임](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) | | 38차시 | 2024.03.08 | BRUTE_FORCE | [자물쇠와 열쇠](https://school.programmers.co.kr/learn/courses/30/lessons/60059) | [#154](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/154) | -| 39차시 | 2024.03.19 | 큐 | [디스크 컨트롤러](https://school.programmers.co.kr/learn/courses/30/lessons/42627) | [#163](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/163) | \ No newline at end of file +| 39차시 | 2024.03.19 | 큐 | [디스크 컨트롤러](https://school.programmers.co.kr/learn/courses/30/lessons/42627) | [#163](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/163) | +| 40차시 | 2024.03.22 | 그리디 | [센서](https://www.acmicpc.net/problem/2212) | [#168](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/168) | \ No newline at end of file diff --git "a/pknujsp/\352\267\270\353\246\254\353\224\224/40-\354\204\274\354\204\234.py" "b/pknujsp/\352\267\270\353\246\254\353\224\224/40-\354\204\274\354\204\234.py" new file mode 100644 index 00000000..07494620 --- /dev/null +++ "b/pknujsp/\352\267\270\353\246\254\353\224\224/40-\354\204\274\354\204\234.py" @@ -0,0 +1,18 @@ +from sys import * + +N = int(stdin.readline()) +K = int(stdin.readline()) +SENSORS = sorted(set(map(int, stdin.readline().split()))) + +if K >= N: + print(0) + exit() + +distances = [SENSORS[i] - SENSORS[i - 1] for i in range(1, len(SENSORS))] +distances.sort(reverse=True) + +result = 0 +for i in range(K - 1, len(distances)): + result += distances[i] + +print(result)