We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8d81cc5 commit 3e4f36fCopy full SHA for 3e4f36f
minjeong/Greedy/2024-11-14-[백준]-#2212-센서.py
@@ -0,0 +1,21 @@
1
+import sys
2
+input = sys.stdin.readline
3
+
4
+n = int(input()) # 센서의 개수
5
+k = int(input()) # 집중국의 개수
6
+pos = list(map(int, input().split())) # 센서의 좌표
7
8
+pos = sorted(set(pos)) # 센서 위치 정렬 및 중복 제거
9
+distances = [] # 센서 간 거리 차이
10
11
+# 센서 간 거리 차이 계산
12
+for i in range(1, len(pos)):
13
+ distances.append(pos[i] - pos[i-1])
14
15
+# 거리 차이 큰 순서로 정렬
16
+distances.sort(reverse=True)
17
18
+# 가장 큰 (k-1)개의 거리 차이를 빼고 남은 거리들의 합이 최소가 되는 거리 합
19
+min_dist_sum = sum(distances[k-1:])
20
21
+print(min_dist_sum)
0 commit comments