From 974f4724f4340be24ff0f56d670fbff12a1d6ee4 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sat, 29 Nov 2025 11:23:22 +0900 Subject: [PATCH] =?UTF-8?q?[20251129]=20BOJ=20/=20G5=20/=20=EB=82=9C?= =?UTF-8?q?=EB=A1=9C=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../29 BOJ \353\202\234\353\241\234.md" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "0224LJH/202511/29 BOJ \353\202\234\353\241\234.md" diff --git "a/0224LJH/202511/29 BOJ \353\202\234\353\241\234.md" "b/0224LJH/202511/29 BOJ \353\202\234\353\241\234.md" new file mode 100644 index 00000000..47a27f41 --- /dev/null +++ "b/0224LJH/202511/29 BOJ \353\202\234\353\241\234.md" @@ -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 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); + } + +} + +```