Skip to content

Commit 249b2b9

Browse files
committed
do : 2023-01-29 #24
1 parent 0ee3e6a commit 249b2b9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/main/kotlin/BOJ/greedy/13164.kt

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package BOJ.greedy
2+
3+
import java.util.LinkedList
4+
import java.util.PriorityQueue
5+
import java.util.StringTokenizer
6+
import kotlin.time.Duration.Companion.seconds
7+
8+
fun main(){
9+
P13164().solution()
10+
}
11+
12+
class P13164 {
13+
fun solution() = with(System.`in`.bufferedReader()){
14+
val st = StringTokenizer(readLine() , " ")
15+
val N = st.nextToken().toInt()
16+
val total = st.nextToken().toInt()
17+
val group = readLine().split(" ").map{it.toLong()}.toMutableList()
18+
val gap = LongArray(N-1){0}
19+
for(i in 0 until group.size-1){
20+
gap[i]=(group[i+1]-group[i])
21+
}
22+
gap.sort()
23+
var result = 0L
24+
25+
for(j in 0 until N-total){
26+
result+=gap[j]
27+
}
28+
println(result)
29+
30+
}
31+
}

0 commit comments

Comments
 (0)