結果

問題 No.2093 Shio Ramen
ユーザー 👑 箱星箱星
提出日時 2022-10-05 21:29:35
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 14,158 ms
コンパイル使用メモリ 430,768 KB
実行使用メモリ 59,260 KB
最終ジャッジ日時 2023-08-30 21:09:19
合計ジャッジ時間 26,367 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 305 ms
57,908 KB
testcase_01 AC 313 ms
56,148 KB
testcase_02 AC 307 ms
58,080 KB
testcase_03 AC 303 ms
56,112 KB
testcase_04 AC 302 ms
55,860 KB
testcase_05 AC 305 ms
56,452 KB
testcase_06 AC 307 ms
56,216 KB
testcase_07 AC 304 ms
57,868 KB
testcase_08 AC 306 ms
57,976 KB
testcase_09 AC 354 ms
59,080 KB
testcase_10 AC 354 ms
57,248 KB
testcase_11 AC 319 ms
58,744 KB
testcase_12 AC 345 ms
57,004 KB
testcase_13 AC 335 ms
56,868 KB
testcase_14 AC 342 ms
56,828 KB
testcase_15 AC 362 ms
58,764 KB
testcase_16 AC 356 ms
57,228 KB
testcase_17 AC 363 ms
59,200 KB
testcase_18 AC 361 ms
57,656 KB
testcase_19 AC 365 ms
59,260 KB
testcase_20 AC 365 ms
59,104 KB
testcase_21 AC 363 ms
57,380 KB
testcase_22 AC 360 ms
57,264 KB
testcase_23 AC 360 ms
58,876 KB
testcase_24 AC 361 ms
59,152 KB
testcase_25 AC 361 ms
57,252 KB
testcase_26 AC 363 ms
57,220 KB
testcase_27 AC 364 ms
57,272 KB
testcase_28 AC 361 ms
58,612 KB
testcase_29 AC 363 ms
59,152 KB
testcase_30 AC 360 ms
57,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    val l = nextInt()
    val (s, a) = Array(n) { nextInt() to nextInt() }.unzip().toList().map { it.toTypedArray() }
    val dp = Array(n + 1) { IntArray(l + 1) { 0 } }
    for (i in 0 until n) {
        for (j in 0..l) {
            if (j >= s[i]) {
                dp[i + 1][j] = maxOf(dp[i + 1][j], dp[i][j], dp[i][j - s[i]] + a[i])
            } else {
                dp[i + 1][j] = maxOf(dp[i + 1][j], dp[i][j])
            }
        }
    }
    println(dp[n].maxOrNull())
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", abs(1L.shl(26)))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion
0