From 56700442a1470b2a9e8149487e82c946e7f91679 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Fri, 18 Jul 2025 15:23:47 +0900 Subject: [PATCH] =?UTF-8?q?[20250718]=20BOJ=20/=20G5=20/=20=ED=96=89?= =?UTF-8?q?=EB=B3=B5=20=EC=9C=A0=EC=B9=98=EC=9B=90=20/=20=EA=B9=80?= =?UTF-8?q?=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5 \354\234\240\354\271\230\354\233\220.md" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "suyeun84/202507/18 BOJ G5 \355\226\211\353\263\265 \354\234\240\354\271\230\354\233\220.md" diff --git "a/suyeun84/202507/18 BOJ G5 \355\226\211\353\263\265 \354\234\240\354\271\230\354\233\220.md" "b/suyeun84/202507/18 BOJ G5 \355\226\211\353\263\265 \354\234\240\354\271\230\354\233\220.md" new file mode 100644 index 00000000..bc304e2a --- /dev/null +++ "b/suyeun84/202507/18 BOJ G5 \355\226\211\353\263\265 \354\234\240\354\271\230\354\233\220.md" @@ -0,0 +1,28 @@ +```java +import java.util.*; +import java.io.*; + +public class boj13164 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + public static void main(String[] args) throws Exception { + int N, K, answer = 0; + nextLine(); + N = nextInt(); + K = nextInt(); + nextLine(); + int[] h = new int[N]; + for (int i = 0; i < N; i++) h[i] = nextInt(); + + int[] diff = new int[N - 1]; + for (int i = 0; i < N - 1; i++) diff[i] = h[i + 1] - h[i]; + + Arrays.sort(diff); + for (int i = 0; i < N - K; i++) answer += diff[i]; + System.out.println(answer); + } +} +```