Skip to content

Commit 974f472

Browse files
authored
[20251129] BOJ / G5 / 난로 / 이종환
1 parent d3c166a commit 974f472

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

0224LJH/202511/29 BOJ 난로.md

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

0 commit comments

Comments
 (0)