結果

問題 No.2408 Lakes and Fish
ユーザー simansiman
提出日時 2023-08-12 21:35:06
言語 Ruby
(3.3.0)
結果
AC  
実行時間 481 ms / 2,000 ms
コード長 545 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 28,668 KB
最終ジャッジ日時 2023-08-12 21:35:16
合計ジャッジ時間 9,831 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
15,100 KB
testcase_01 AC 72 ms
15,056 KB
testcase_02 AC 72 ms
15,036 KB
testcase_03 AC 73 ms
15,116 KB
testcase_04 AC 454 ms
28,544 KB
testcase_05 AC 430 ms
28,484 KB
testcase_06 AC 441 ms
28,224 KB
testcase_07 AC 447 ms
28,608 KB
testcase_08 AC 459 ms
28,484 KB
testcase_09 AC 481 ms
28,556 KB
testcase_10 AC 464 ms
28,668 KB
testcase_11 AC 281 ms
20,600 KB
testcase_12 AC 355 ms
25,028 KB
testcase_13 AC 142 ms
18,624 KB
testcase_14 AC 225 ms
20,732 KB
testcase_15 AC 391 ms
24,132 KB
testcase_16 AC 165 ms
22,196 KB
testcase_17 AC 151 ms
17,232 KB
testcase_18 AC 264 ms
22,548 KB
testcase_19 AC 360 ms
23,264 KB
testcase_20 AC 384 ms
21,744 KB
testcase_21 AC 413 ms
24,044 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
L = gets.split.map(&:to_i)
lake = L.tally
L << Float::INFINITY
Q = M.times.map { gets.split.map(&:to_i) }

ans = 0

Q.each do |f, b, w|
  idx = L.bsearch_index { |l| l >= f }

  if lake[f]
    ans += w
  else
    cur_power = b

    if L[idx] != Float::INFINITY
      d = L[idx] - f

      if cur_power < w - d 
        cur_power = w - d
      end
    end

    if idx - 1 >= 0
      d = f - L[idx - 1]

      if cur_power < w - d
        cur_power = w - d
      end
    end

    ans += cur_power
  end
end

puts ans
0