結果

問題 No.1858 Gorgeous Knapsack
ユーザー yudedakoyudedako
提出日時 2022-03-14 16:26:51
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,174 ms / 2,000 ms
コード長 676 bytes
コンパイル時間 15,221 ms
コンパイル使用メモリ 271,292 KB
実行使用メモリ 65,620 KB
最終ジャッジ日時 2023-10-20 08:01:57
合計ジャッジ時間 59,948 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 952 ms
65,164 KB
testcase_01 AC 960 ms
65,136 KB
testcase_02 AC 958 ms
65,136 KB
testcase_03 AC 966 ms
65,228 KB
testcase_04 AC 1,043 ms
65,556 KB
testcase_05 AC 1,010 ms
65,552 KB
testcase_06 AC 1,073 ms
65,568 KB
testcase_07 AC 1,076 ms
65,580 KB
testcase_08 AC 1,076 ms
65,600 KB
testcase_09 AC 1,109 ms
65,620 KB
testcase_10 AC 1,084 ms
65,576 KB
testcase_11 AC 1,098 ms
65,600 KB
testcase_12 AC 1,093 ms
65,612 KB
testcase_13 AC 1,104 ms
65,616 KB
testcase_14 AC 956 ms
65,164 KB
testcase_15 AC 946 ms
65,192 KB
testcase_16 AC 945 ms
65,204 KB
testcase_17 AC 953 ms
65,184 KB
testcase_18 AC 964 ms
65,204 KB
testcase_19 AC 941 ms
65,216 KB
testcase_20 AC 951 ms
65,168 KB
testcase_21 AC 948 ms
65,188 KB
testcase_22 AC 939 ms
65,156 KB
testcase_23 AC 965 ms
65,128 KB
testcase_24 AC 1,022 ms
65,536 KB
testcase_25 AC 1,099 ms
65,572 KB
testcase_26 AC 1,070 ms
65,544 KB
testcase_27 AC 1,066 ms
65,572 KB
testcase_28 AC 1,082 ms
65,608 KB
testcase_29 AC 1,046 ms
65,572 KB
testcase_30 AC 1,071 ms
65,576 KB
testcase_31 AC 1,083 ms
65,564 KB
testcase_32 AC 1,069 ms
65,572 KB
testcase_33 AC 1,085 ms
65,572 KB
testcase_34 AC 1,174 ms
65,608 KB
testcase_35 AC 1,076 ms
65,620 KB
testcase_36 AC 1,151 ms
65,584 KB
testcase_37 AC 951 ms
65,144 KB
testcase_38 AC 1,060 ms
65,572 KB
testcase_39 AC 979 ms
65,196 KB
testcase_40 AC 1,070 ms
65,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import scala.collection.mutable.*
import scala.io.StdIn.*
import scala.util.chaining.*
import scala.math.*
import scala.reflect.ClassTag
import scala.util.*
import scala.annotation.tailrec
import scala.collection.mutable


@main def main() =
  val Array(n, m) = readLine().split(' ').map(_.toInt)
  val jewels = Array.fill(n){
    val Array(v, w) = readLine().split(' ').map(_.toInt)
    v -> w
  }
  val memo = Array.fill(m + 1){0L}
  var result = 0L
  for (v, w) <- jewels.sortBy(_._1)(Ordering[Int].reverse) do
    for i <- m to w by -1 do
      memo(i) = max(memo(i), memo(i - w) + v)
    result = max(result, v * memo.last)
  println(result)

0