Skip to content

Commit

Permalink
do : 2023-01-29 #24
Browse files Browse the repository at this point in the history
  • Loading branch information
HyomK committed Jan 28, 2023
1 parent 0ee3e6a commit 249b2b9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/main/kotlin/BOJ/greedy/13164.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package BOJ.greedy

import java.util.LinkedList
import java.util.PriorityQueue
import java.util.StringTokenizer
import kotlin.time.Duration.Companion.seconds

fun main(){
P13164().solution()
}

class P13164 {
fun solution() = with(System.`in`.bufferedReader()){
val st = StringTokenizer(readLine() , " ")
val N = st.nextToken().toInt()
val total = st.nextToken().toInt()
val group = readLine().split(" ").map{it.toLong()}.toMutableList()
val gap = LongArray(N-1){0}
for(i in 0 until group.size-1){
gap[i]=(group[i+1]-group[i])
}
gap.sort()
var result = 0L

for(j in 0 until N-total){
result+=gap[j]
}
println(result)

}
}

0 comments on commit 249b2b9

Please sign in to comment.