# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
377321 | 2021-03-13T23:22:54 Z | timg8710 | Stove (JOI18_stove) | Java 11 | 0 ms | 0 KB |
// package olypmiads; import java.io.*; import java.util.*; public class stovejoi { 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(); } }