Skip to content

Commit 7df27ba

Browse files
authored
Merge pull request #246 from AlgorithmWithGod/khj20006
[20250314] BOJ / G5 / 난로 / 권혁준
2 parents b45b8bb + c746861 commit 7df27ba

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
```

0 commit comments

Comments
 (0)