Skip to content

Commit 5670044

Browse files
authored
[20250718] BOJ / G5 / 행복 유치원 / 김수연
1 parent 49e0053 commit 5670044

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class boj13164 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
int N, K, answer = 0;
13+
nextLine();
14+
N = nextInt();
15+
K = nextInt();
16+
nextLine();
17+
int[] h = new int[N];
18+
for (int i = 0; i < N; i++) h[i] = nextInt();
19+
20+
int[] diff = new int[N - 1];
21+
for (int i = 0; i < N - 1; i++) diff[i] = h[i + 1] - h[i];
22+
23+
Arrays.sort(diff);
24+
for (int i = 0; i < N - K; i++) answer += diff[i];
25+
System.out.println(answer);
26+
}
27+
}
28+
```

0 commit comments

Comments
 (0)