結果

問題 No.1163 I want to be a high achiever
ユーザー yuruhiyayuruhiya
提出日時 2020-08-12 11:25:17
言語 Crystal
(1.11.2)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 411 bytes
コンパイル時間 17,586 ms
コンパイル使用メモリ 256,156 KB
実行使用メモリ 5,184 KB
最終ジャッジ日時 2023-09-13 11:35:41
合計ジャッジ時間 20,726 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,980 KB
testcase_01 AC 2 ms
4,392 KB
testcase_02 AC 2 ms
4,452 KB
testcase_03 AC 7 ms
5,072 KB
testcase_04 AC 87 ms
5,056 KB
testcase_05 AC 103 ms
5,072 KB
testcase_06 AC 67 ms
4,976 KB
testcase_07 AC 111 ms
5,052 KB
testcase_08 AC 113 ms
5,092 KB
testcase_09 AC 2 ms
4,464 KB
testcase_10 AC 90 ms
4,936 KB
testcase_11 AC 105 ms
5,008 KB
testcase_12 AC 89 ms
5,008 KB
testcase_13 AC 70 ms
5,076 KB
testcase_14 AC 72 ms
5,120 KB
testcase_15 AC 109 ms
5,076 KB
testcase_16 AC 81 ms
5,096 KB
testcase_17 AC 93 ms
5,028 KB
testcase_18 AC 111 ms
4,992 KB
testcase_19 AC 71 ms
5,172 KB
testcase_20 AC 64 ms
5,168 KB
testcase_21 AC 2 ms
4,504 KB
testcase_22 AC 99 ms
5,116 KB
testcase_23 AC 94 ms
5,108 KB
testcase_24 AC 112 ms
5,020 KB
testcase_25 AC 84 ms
5,140 KB
testcase_26 AC 2 ms
4,504 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 4 ms
5,184 KB
testcase_30 AC 3 ms
5,060 KB
testcase_31 AC 3 ms
4,384 KB
testcase_32 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, x = read_line.split.map &.to_i
ab = (1..2).map { read_line.split.map &.to_i }.transpose.map { |(a, b)| {a - x, b} }
goal = -ab.sum(&.[0])
if goal <= 0
  puts 0
elsif ab.none? { |a, b| a >= 0 }
  puts -1
else
  dp = [0] + [10**9] * (500 * 100)
  ab.select { |a, b| a < 0 }.each { |a, b|
    (0...dp.size + a).reverse_each { |i|
      dp[i - a] = {dp[i - a], dp[i] + b}.min
    }
  }
  puts dp[goal..].min
end
0