From 072376f821a5080e427fc74f891b98ca0b12839c Mon Sep 17 00:00:00 2001 From: yenru0 Date: Mon, 3 Nov 2025 16:21:42 +0900 Subject: [PATCH] complete 1202.kt --- storage/zeta/kt/completed/1202.kt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 storage/zeta/kt/completed/1202.kt 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