Skip to content

Commit

Permalink
solve: 호텔
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg3410 committed Apr 21, 2024
1 parent 1e4b44f commit fc8215d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/kotlin/heejik/59week/호텔.kt
Original file line number Diff line number Diff line change
@@ -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<Int>()
val customers = mutableListOf<Int>()
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()
}

0 comments on commit fc8215d

Please sign in to comment.