complete 1202.kt
This commit is contained in:
31
storage/zeta/kt/completed/1202.kt
Normal file
31
storage/zeta/kt/completed/1202.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
import java.util.PriorityQueue
|
||||
|
||||
fun main() = with(System.`in`.bufferedReader()) {
|
||||
val (n, k) = this.readLine().split(' ').map { it.toInt() }
|
||||
|
||||
val items = (1..n).map {
|
||||
this.readLine().split(' ').let {
|
||||
it[0].toInt() to it[1].toInt()
|
||||
}
|
||||
}.sortedBy { it.first /* weight */ }
|
||||
|
||||
val capacities = (1..k).map {
|
||||
this.readLine().toInt()
|
||||
}.sortedBy { it }
|
||||
|
||||
val heap = PriorityQueue<Int>(Comparator.reverseOrder<Int>())
|
||||
|
||||
var curr = 0
|
||||
var total_value = 0L
|
||||
for (cap in capacities) {
|
||||
while (curr < n && cap >= items[curr].first) {
|
||||
heap.add(items[curr].second)
|
||||
curr++;
|
||||
}
|
||||
heap.poll()?.let {
|
||||
total_value += it
|
||||
}
|
||||
}
|
||||
|
||||
println(total_value)
|
||||
}
|
||||
Reference in New Issue
Block a user