結果

問題 No.489 株に挑戦
ユーザー 👑 obakyanobakyan
提出日時 2019-05-02 15:25:08
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 92 ms / 1,000 ms
コード長 1,711 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 06:01:39
合計ジャッジ時間 2,501 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
4,376 KB
testcase_01 AC 33 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 61 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 20 ms
4,376 KB
testcase_19 AC 25 ms
4,376 KB
testcase_20 AC 56 ms
4,376 KB
testcase_21 AC 12 ms
4,376 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 16 ms
4,380 KB
testcase_24 AC 81 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 82 ms
4,380 KB
testcase_27 AC 35 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 89 ms
4,380 KB
testcase_31 AC 92 ms
4,376 KB
testcase_32 AC 21 ms
4,380 KB
testcase_33 AC 75 ms
4,376 KB
testcase_34 AC 46 ms
4,376 KB
testcase_35 AC 19 ms
4,380 KB
testcase_36 AC 10 ms
4,376 KB
testcase_37 AC 35 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local ior = io.input()
local n, d, k = ior:read("*n", "*n", "*n")
local t = {}
for i = 1, n do t[i] = ior:read("*n") end
local ret_stt_pos = 1
local ret_val = 0
local mma, mmi, mce = math.max, math.min, math.ceil
if(d < 50) then
  for i = 1, n - 1 do
    local max = 0
    local lst = mmi(n, i + d)
    for j = i + 1, lst do
      max = mma(max, t[j])
    end
    if(ret_val < max - t[i]) then
      ret_val = max - t[i]
      ret_stt_pos = i
    end
  end
else
  local sqd = math.floor(math.sqrt(d))
  local blockmax = {}
  local blockcount = mce(n / sqd)
  for i = 1, blockcount do blockmax[i] = 0 end
  for i = 1, n do
    local b_idx = mce(i / sqd)
    blockmax[b_idx] = mma(blockmax[b_idx], t[i])
  end
  for i = 1, n - 1 do
    local max = 0
    local lst = mmi(n, i + d)
    local block_start_idx = mce(i / sqd) + 1
    local block_end_idx = mce(lst / sqd) - 1
    local block_start_pos = (block_start_idx - 1) * sqd + 1
    block_start_pos = mmi(n + 1, block_start_pos)
    local block_end_pos = block_end_idx * sqd
    for j = block_start_idx, block_end_idx do
      max = mma(max, blockmax[j])
    end
    for j = i + 1, block_start_pos - 1 do
      max = mma(max, t[j])
    end
    if(block_start_idx <= block_end_idx) then
      for j = block_end_pos + 1, lst do
        max = mma(max, t[j])
      end
    end
    if(ret_val < max - t[i]) then
      ret_val = max - t[i]
      ret_stt_pos = i
    end
  end
end
print(ret_val * k)
if(0 < ret_val) then
  local max = t[ret_stt_pos + 1]
  local maxj = ret_stt_pos + 1
  local lst = mmi(n, ret_stt_pos + d)
  for j = ret_stt_pos + 1, lst do
    if(max < t[j]) then
      max, maxj = t[j], j
    end
  end
  print(ret_stt_pos - 1 .. " " .. maxj - 1)
end
0