This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
class stove {
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);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |