diff --git a/storage/zeta/kt/completed/1202.kt b/storage/zeta/kt/completed/1202.kt new file mode 100644 index 0000000..4e02b8d --- /dev/null +++ b/storage/zeta/kt/completed/1202.kt @@ -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(Comparator.reverseOrder()) + + 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) +} \ No newline at end of file