This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// package olypmiads;
import java.io.*;
import java.util.*;
@SuppressWarnings("unchecked")
public class stove {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken())-1;
List<Integer> gaps = new ArrayList();
int c = Integer.parseInt(br.readLine());
int ret = 1;
for(int i = 0; i<N-1; i++){
int n = Integer.parseInt(br.readLine());
gaps.add(n - c - 1);
ret += n - c;
c = n;
}
Collections.sort(gaps, Collections.reverseOrder());
for(int i = 0; i<Math.min(K, gaps.size()); i++) ret -= gaps.get(i);
pw.println(ret);
pw.close();
br.close();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |