import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
class Main {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int K = scanner.nextInt();
ArrayList<Integer> times = new ArrayList<>();
for (int i = 0; i < N; i++) {
int arrival = scanner.nextInt();
times.add(arrival);
}
int length = times.get(N-1) + 1 - times.get(0);
ArrayList<Integer> diffTimes = new ArrayList<>();
for (int i=1; i < times.size(); i++) {
diffTimes.add(times.get(i) - times.get(i-1) - 1);
}
Collections.sort(diffTimes);
int sum = 0;
for (int i = N-K; i < N-1; i++) {
sum += diffTimes.get(i);
}
System.out.println(length - sum);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
134 ms |
12276 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
134 ms |
12276 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
134 ms |
12276 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |