File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments