File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed
Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+
7+
8+ static int len, blockCnt;
9+ static long total;
10+ static long [] arr,diff;
11+
12+ public static void main (String [] args ) throws NumberFormatException , IOException {
13+ init();
14+ process();
15+ print();
16+
17+
18+
19+ }
20+
21+ public static void init () throws IOException {
22+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
23+ StringTokenizer st = new StringTokenizer (br. readLine());
24+ len = Integer . parseInt(st. nextToken());
25+ blockCnt = Integer . parseInt(st. nextToken());
26+ arr = new long [len];
27+ total = 1 ;
28+ for (int i = 0 ; i < len; i++ ) {
29+ arr[i] = Long . parseLong(br. readLine());
30+ }
31+
32+ }
33+
34+ public static void process () {
35+ PriorityQueue<Long > q = new PriorityQueue<> (Collections . reverseOrder());
36+ for (int i = 0 ; i < len- 1 ; i++ ) {
37+ q. add(arr[i+ 1 ]- arr[i]);
38+ }
39+
40+ for (int i = 0 ; i < len- 1 ; i++ ) {
41+ long cost = q. poll();
42+ if (i < blockCnt - 1 ) cost = 1 ;
43+ total += cost;
44+ }
45+
46+ }
47+
48+
49+
50+ public static void print () {
51+ System . out. println(total);
52+ }
53+
54+ }
55+
56+ ```
You can’t perform that action at this time.
0 commit comments