From fc8215d02b639ba5d53acefefc441ae9e0560005 Mon Sep 17 00:00:00 2001 From: jhg3410 Date: Sun, 21 Apr 2024 13:55:52 +0900 Subject: [PATCH] =?UTF-8?q?solve:=20=ED=98=B8=ED=85=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../59week/\355\230\270\355\205\224.kt" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "src/main/kotlin/heejik/59week/\355\230\270\355\205\224.kt" diff --git "a/src/main/kotlin/heejik/59week/\355\230\270\355\205\224.kt" "b/src/main/kotlin/heejik/59week/\355\230\270\355\205\224.kt" new file mode 100644 index 00000000..c0e066d8 --- /dev/null +++ "b/src/main/kotlin/heejik/59week/\355\230\270\355\205\224.kt" @@ -0,0 +1,40 @@ +package heejik.`59week` + +import kotlin.math.max + +class 호텔 { + + fun solve() { + val (c, n) = readln().split(' ').map { it.toInt() } + val dp = List(n) { MutableList(size = 100001) { 0 } } + val prices = mutableListOf() + val customers = mutableListOf() + repeat(n) { idx -> + val (price, customer) = readln().split(' ').map { it.toInt() } + dp[idx][price] = customer + prices.add(price) + customers.add(customer) + } + for (i in 0 until n) { + for (j in 1 until 100001) { + if (i == 0) { + if (j - prices[i] >= 0) { + dp[i][j] = dp[i][j - prices[i]] + customers[i] + } + } else { + if (j - prices[i] >= 0) { + dp[i][j] = max(dp[i - 1][j], dp[i][j - prices[i]] + customers[i]) + } else { + dp[i][j] = max(dp[i - 1][j], dp[i][j]) + } + } + } + } + + print(dp[n - 1].indexOfFirst { it >= c }) + } +} + +fun main() { + 호텔().solve() +} \ No newline at end of file