結果

問題 No.844 split game
ユーザー 👑 obakyanobakyan
提出日時 2019-06-30 00:34:48
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 322 ms / 2,000 ms
コード長 1,063 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 20,940 KB
最終ジャッジ日時 2023-09-14 23:25:17
合計ジャッジ時間 8,222 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
10,240 KB
testcase_01 AC 78 ms
9,160 KB
testcase_02 AC 289 ms
18,860 KB
testcase_03 AC 182 ms
14,588 KB
testcase_04 AC 84 ms
9,092 KB
testcase_05 AC 273 ms
19,308 KB
testcase_06 AC 66 ms
7,964 KB
testcase_07 AC 49 ms
7,612 KB
testcase_08 AC 30 ms
4,840 KB
testcase_09 AC 215 ms
15,144 KB
testcase_10 AC 308 ms
19,644 KB
testcase_11 AC 278 ms
19,420 KB
testcase_12 AC 214 ms
15,200 KB
testcase_13 AC 121 ms
10,052 KB
testcase_14 AC 106 ms
9,780 KB
testcase_15 AC 317 ms
20,800 KB
testcase_16 AC 318 ms
20,928 KB
testcase_17 AC 317 ms
20,784 KB
testcase_18 AC 315 ms
20,940 KB
testcase_19 AC 317 ms
20,940 KB
testcase_20 AC 318 ms
20,816 KB
testcase_21 AC 319 ms
20,820 KB
testcase_22 AC 322 ms
20,844 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 18 ms
4,380 KB
testcase_25 AC 12 ms
4,376 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 16 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 14 ms
4,380 KB
testcase_30 AC 18 ms
4,376 KB
testcase_31 AC 15 ms
4,380 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 26 ms
4,376 KB
testcase_34 AC 15 ms
4,504 KB
testcase_35 AC 31 ms
4,664 KB
testcase_36 AC 18 ms
4,376 KB
testcase_37 AC 47 ms
5,928 KB
testcase_38 AC 102 ms
9,500 KB
testcase_39 AC 234 ms
16,980 KB
testcase_40 AC 51 ms
7,044 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 1 ms
4,380 KB
testcase_53 AC 1 ms
4,376 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,376 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n, m, a = io.read("*n", "*n", "*n")
local t = {}
for i = 1, m do
  t[i] = {}
  t[i].l, t[i].r, t[i].p = io.read("*n", "*n", "*n")
end
table.sort(t, function(x, y)
  if x.r ~= y.r then
    return x.r < y.r
  else
    return x.l < y.l
  end
end)

local mma = math.max
local ret = {}
local inf = -100000000000000
for i = 1, n do ret[i] = inf end
local curmax = {}
local curpos = 1
for i = 1, n do curmax[i] = 0 end
for i = 1, m do
  local l, r, p = t[i].l, t[i].r, t[i].p
  if curpos ~= r then
    for k = curpos + 1, r do
      curmax[k] = mma(curmax[k], curmax[k - 1])
    end
    curpos = r
  end
  local cost = r == n and 0 or a
  if l == 1 then
    ret[r] = mma(ret[r], p - cost)
  else
    -- print(i, l, r, p, ret[l - 1])
    if ret[l - 1] == inf then
      -- ret[r] = mma(ret[r], -a + p - cost)
      ret[l - 1] = curmax[l - 1] - a
    end
    ret[r] = mma(ret[r], mma(curmax[l - 1] - a, ret[l - 1]) + p - cost)
  end
  curmax[r] = mma(curmax[r], ret[r])
end
local tot = 0
for i = 1, n do
  -- print(i, ret[i])
  tot = mma(tot, ret[i])
end
print(tot)
0