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); + } +} +```