Skip to content

Commit

Permalink
solve(BOJ): G3_7579_앱_kt
Browse files Browse the repository at this point in the history
  • Loading branch information
gogumaC committed Feb 9, 2024
1 parent 5e2255f commit e3a235c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/boj/G3_7579_앱.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package boj

import java.util.*
import kotlin.math.max

class BOJ7579() {
fun solve() {
val st = StringTokenizer(readln())
val N = st.nextToken().toInt()
val M = st.nextToken().toInt()

val mem = IntArray(N + 1)
val cost = IntArray(N + 1)

val st1 = StringTokenizer(readln())
val st2 = StringTokenizer(readln())

for (i in 1..N) {
mem[i] = st1.nextToken().toInt()
cost[i] = st2.nextToken().toInt()
}

val maxCost = 10000
val dp = Array(N + 1) { IntArray(maxCost + 1) }

for (i in 1..N) {
for (j in 0..maxCost) {
if (cost[i] > j) {
dp[i][j] = dp[i - 1][j]
} else {
val takeout = dp[i - 1][j]
val putin = mem[i] + dp[i - 1][j - cost[i]]
dp[i][j] = max(takeout, putin)
}

if (i == N && dp[i][j] >= M) {
println(j)
return
}

}
}
}
}

fun main() {
BOJ7579().solve()
}

0 comments on commit e3a235c

Please sign in to comment.