import java.io.*;
import java.util.*;
public class stove {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
StringTokenizer stk = new StringTokenizer(bf.readLine());
int N = Integer.parseInt(stk.nextToken());
int K = Integer.parseInt(stk.nextToken());
int[] guests = new int[N];
for(int i = 0; i < N; i++)guests[i] = Integer.parseInt(bf.readLine());
Arrays.sort(guests);
PriorityQueue<Integer> gaps = new PriorityQueue<>();
for(int i = 0; i < N-1; i++)gaps.add(guests[i+1] - guests[i]);
int matchesusing = N;
long answer = N;
while(matchesusing != K){
answer += gaps.poll()-1;
matchesusing--;
}
System.out.println(answer);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
10344 KB |
Output is correct |
2 |
Correct |
80 ms |
10356 KB |
Output is correct |
3 |
Correct |
79 ms |
10360 KB |
Output is correct |
4 |
Correct |
79 ms |
10104 KB |
Output is correct |
5 |
Correct |
76 ms |
10488 KB |
Output is correct |
6 |
Correct |
77 ms |
10276 KB |
Output is correct |
7 |
Correct |
78 ms |
10468 KB |
Output is correct |
8 |
Correct |
76 ms |
10360 KB |
Output is correct |
9 |
Correct |
77 ms |
10360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
10344 KB |
Output is correct |
2 |
Correct |
80 ms |
10356 KB |
Output is correct |
3 |
Correct |
79 ms |
10360 KB |
Output is correct |
4 |
Correct |
79 ms |
10104 KB |
Output is correct |
5 |
Correct |
76 ms |
10488 KB |
Output is correct |
6 |
Correct |
77 ms |
10276 KB |
Output is correct |
7 |
Correct |
78 ms |
10468 KB |
Output is correct |
8 |
Correct |
76 ms |
10360 KB |
Output is correct |
9 |
Correct |
77 ms |
10360 KB |
Output is correct |
10 |
Correct |
123 ms |
12232 KB |
Output is correct |
11 |
Correct |
116 ms |
12024 KB |
Output is correct |
12 |
Correct |
138 ms |
12696 KB |
Output is correct |
13 |
Correct |
117 ms |
11252 KB |
Output is correct |
14 |
Correct |
112 ms |
11640 KB |
Output is correct |
15 |
Correct |
116 ms |
12732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
10344 KB |
Output is correct |
2 |
Correct |
80 ms |
10356 KB |
Output is correct |
3 |
Correct |
79 ms |
10360 KB |
Output is correct |
4 |
Correct |
79 ms |
10104 KB |
Output is correct |
5 |
Correct |
76 ms |
10488 KB |
Output is correct |
6 |
Correct |
77 ms |
10276 KB |
Output is correct |
7 |
Correct |
78 ms |
10468 KB |
Output is correct |
8 |
Correct |
76 ms |
10360 KB |
Output is correct |
9 |
Correct |
77 ms |
10360 KB |
Output is correct |
10 |
Correct |
123 ms |
12232 KB |
Output is correct |
11 |
Correct |
116 ms |
12024 KB |
Output is correct |
12 |
Correct |
138 ms |
12696 KB |
Output is correct |
13 |
Correct |
117 ms |
11252 KB |
Output is correct |
14 |
Correct |
112 ms |
11640 KB |
Output is correct |
15 |
Correct |
116 ms |
12732 KB |
Output is correct |
16 |
Correct |
360 ms |
26584 KB |
Output is correct |
17 |
Correct |
336 ms |
25992 KB |
Output is correct |
18 |
Correct |
346 ms |
26708 KB |
Output is correct |
19 |
Correct |
314 ms |
26764 KB |
Output is correct |
20 |
Correct |
334 ms |
25708 KB |
Output is correct |
21 |
Correct |
282 ms |
26764 KB |
Output is correct |
22 |
Correct |
270 ms |
26548 KB |
Output is correct |
23 |
Correct |
268 ms |
25932 KB |
Output is correct |
24 |
Correct |
262 ms |
26476 KB |
Output is correct |