Submission #311734

# Submission time Handle Problem Language Result Execution time Memory
311734 2020-10-11T09:25:00 Z kubo Stove (JOI18_stove) Java 11
0 / 100
89 ms 10480 KB
import java.io.*;
import java.util.*;

class Solution {

  public static void main(String[] args) {

    Scanner sc = new Scanner(new BufferedInputStream(System.in));
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] diff = new int[n-1];
    int a = sc.nextInt();
    for (int i=1; i<n; ++i) {
      int b = sc.nextInt();
      diff[i-1] = b - a;
      a = b;
    }
    Arrays.sort(diff);
    int j = 0;
    long cost = k;
    while (n>k) {
      cost += diff[j++];
      n--;
    }
    System.out.println(cost);
  }
}
# Verdict Execution time Memory Grader output
1 Runtime error 89 ms 10480 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 89 ms 10480 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 89 ms 10480 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -