Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions 0224LJH/202511/29 BOJ 난로.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
```java
import java.io.*;
import java.util.*;

public class Main {


static int len, blockCnt;
static long total;
static long[] arr,diff;

public static void main (String[] args) throws NumberFormatException, IOException {
init();
process();
print();



}

public static void init() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
len = Integer.parseInt(st.nextToken());
blockCnt = Integer.parseInt(st.nextToken());
arr = new long[len];
total = 1;
for (int i = 0; i < len; i++) {
arr[i] = Long.parseLong(br.readLine());
}

}

public static void process() {
PriorityQueue<Long> q = new PriorityQueue<>(Collections.reverseOrder());
for (int i = 0; i < len-1; i++) {
q.add(arr[i+1]-arr[i]);
}

for (int i = 0; i < len-1; i++) {
long cost = q.poll();
if (i < blockCnt -1) cost =1;
total += cost;
}

}



public static void print() {
System.out.println(total);
}

}

```