Submission #311735

# Submission time Handle Problem Language Result Execution time Memory
311735 2020-10-11T09:29:18 Z kubo Stove (JOI18_stove) Java 11
100 / 100
803 ms 57140 KB
import java.io.*;
import java.util.*;

class stove {

  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 Correct 118 ms 11904 KB Output is correct
2 Correct 112 ms 11508 KB Output is correct
3 Correct 119 ms 11620 KB Output is correct
4 Correct 118 ms 11620 KB Output is correct
5 Correct 116 ms 11412 KB Output is correct
6 Correct 112 ms 11496 KB Output is correct
7 Correct 116 ms 11636 KB Output is correct
8 Correct 118 ms 11512 KB Output is correct
9 Correct 114 ms 11504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 11904 KB Output is correct
2 Correct 112 ms 11508 KB Output is correct
3 Correct 119 ms 11620 KB Output is correct
4 Correct 118 ms 11620 KB Output is correct
5 Correct 116 ms 11412 KB Output is correct
6 Correct 112 ms 11496 KB Output is correct
7 Correct 116 ms 11636 KB Output is correct
8 Correct 118 ms 11512 KB Output is correct
9 Correct 114 ms 11504 KB Output is correct
10 Correct 271 ms 21456 KB Output is correct
11 Correct 258 ms 21032 KB Output is correct
12 Correct 290 ms 21248 KB Output is correct
13 Correct 283 ms 20620 KB Output is correct
14 Correct 225 ms 20992 KB Output is correct
15 Correct 277 ms 21132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 11904 KB Output is correct
2 Correct 112 ms 11508 KB Output is correct
3 Correct 119 ms 11620 KB Output is correct
4 Correct 118 ms 11620 KB Output is correct
5 Correct 116 ms 11412 KB Output is correct
6 Correct 112 ms 11496 KB Output is correct
7 Correct 116 ms 11636 KB Output is correct
8 Correct 118 ms 11512 KB Output is correct
9 Correct 114 ms 11504 KB Output is correct
10 Correct 271 ms 21456 KB Output is correct
11 Correct 258 ms 21032 KB Output is correct
12 Correct 290 ms 21248 KB Output is correct
13 Correct 283 ms 20620 KB Output is correct
14 Correct 225 ms 20992 KB Output is correct
15 Correct 277 ms 21132 KB Output is correct
16 Correct 803 ms 56724 KB Output is correct
17 Correct 748 ms 56300 KB Output is correct
18 Correct 796 ms 56500 KB Output is correct
19 Correct 785 ms 55488 KB Output is correct
20 Correct 798 ms 57140 KB Output is correct
21 Correct 769 ms 54804 KB Output is correct
22 Correct 779 ms 56636 KB Output is correct
23 Correct 747 ms 55264 KB Output is correct
24 Correct 735 ms 56868 KB Output is correct