-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} | ||
} |