結果

問題 No.2408 Lakes and Fish
ユーザー simansiman
提出日時 2023-08-12 21:35:06
言語 Ruby
(3.3.0)
結果
AC  
実行時間 567 ms / 2,000 ms
コード長 545 bytes
コンパイル時間 48 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2024-04-30 16:40:26
合計ジャッジ時間 9,761 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
12,288 KB
testcase_01 AC 89 ms
12,160 KB
testcase_02 AC 89 ms
12,160 KB
testcase_03 AC 89 ms
12,160 KB
testcase_04 AC 530 ms
26,368 KB
testcase_05 AC 532 ms
26,240 KB
testcase_06 AC 526 ms
26,752 KB
testcase_07 AC 563 ms
26,880 KB
testcase_08 AC 560 ms
26,880 KB
testcase_09 AC 567 ms
26,624 KB
testcase_10 AC 563 ms
26,880 KB
testcase_11 AC 330 ms
18,516 KB
testcase_12 AC 417 ms
25,344 KB
testcase_13 AC 172 ms
16,000 KB
testcase_14 AC 270 ms
18,032 KB
testcase_15 AC 467 ms
23,680 KB
testcase_16 AC 198 ms
18,944 KB
testcase_17 AC 188 ms
14,848 KB
testcase_18 AC 293 ms
20,864 KB
testcase_19 AC 442 ms
20,964 KB
testcase_20 AC 430 ms
18,944 KB
testcase_21 AC 446 ms
22,012 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