File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed
Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+
3+ import java.util.* ;
4+ import java.io.* ;
5+
6+ class Main {
7+
8+ // IO field
9+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
10+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
11+ static StringTokenizer st = new StringTokenizer (" " );
12+
13+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
14+ static int nextInt() throws Exception {
15+ if (! st. hasMoreTokens()) nextLine();
16+ return Integer . parseInt(st. nextToken());
17+ }
18+ static long nextLong() throws Exception {
19+ if (! st. hasMoreTokens()) nextLine();
20+ return Long . parseLong(st. nextToken());
21+ }
22+ static void bwEnd() throws Exception {bw. flush();bw. close();}
23+
24+ // Additional field
25+
26+ static int N , K , ans = 0 ;
27+ static PriorityQueue<Integer > Q ;
28+
29+ public static void main(String [] args) throws Exception {
30+
31+ ready();
32+ solve();
33+
34+ bwEnd();
35+
36+ }
37+
38+ static void ready() throws Exception {
39+
40+ N = nextInt();
41+ K = nextInt();
42+ Q = new PriorityQueue<> ();
43+ int prev = nextInt(), now = 0 ;
44+
45+ for (int i= 1 ;i< N ;i++ ) {
46+ now = nextInt();
47+ Q . offer(now- prev- 1 );
48+ prev = now;
49+ }
50+
51+ }
52+
53+ static void solve() throws Exception {
54+
55+ ans = N ;
56+ for (int i= N ;i> K ;i-- ) ans += Q . poll();
57+ bw. write(ans + " \n " );
58+
59+ }
60+
61+ }
62+
63+ ```
You can’t perform that action at this time.
0 commit comments