結果

問題 No.1093 区間の和 / Sum of Range
ユーザー 👑 obakyanobakyan
提出日時 2020-11-26 09:40:00
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 796 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 5,336 KB
実行使用メモリ 4,528 KB
最終ジャッジ日時 2023-10-01 03:15:28
合計ジャッジ時間 5,791 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 66 ms
4,376 KB
testcase_02 AC 25 ms
4,380 KB
testcase_03 AC 61 ms
4,376 KB
testcase_04 AC 38 ms
4,376 KB
testcase_05 AC 87 ms
4,380 KB
testcase_06 AC 22 ms
4,376 KB
testcase_07 AC 50 ms
4,376 KB
testcase_08 AC 68 ms
4,376 KB
testcase_09 AC 63 ms
4,380 KB
testcase_10 AC 65 ms
4,380 KB
testcase_11 AC 73 ms
4,376 KB
testcase_12 AC 84 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 98 ms
4,380 KB
testcase_15 AC 34 ms
4,380 KB
testcase_16 AC 129 ms
4,376 KB
testcase_17 AC 63 ms
4,380 KB
testcase_18 AC 65 ms
4,376 KB
testcase_19 AC 10 ms
4,380 KB
testcase_20 AC 49 ms
4,380 KB
testcase_21 AC 106 ms
4,376 KB
testcase_22 AC 131 ms
4,376 KB
testcase_23 AC 67 ms
4,384 KB
testcase_24 AC 33 ms
4,376 KB
testcase_25 AC 66 ms
4,376 KB
testcase_26 AC 99 ms
4,376 KB
testcase_27 AC 89 ms
4,376 KB
testcase_28 AC 90 ms
4,376 KB
testcase_29 AC 142 ms
4,528 KB
testcase_30 AC 20 ms
4,376 KB
testcase_31 AC 40 ms
4,376 KB
testcase_32 AC 44 ms
4,380 KB
testcase_33 AC 123 ms
4,384 KB
testcase_34 AC 7 ms
4,380 KB
testcase_35 AC 82 ms
4,376 KB
testcase_36 AC 125 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function upper_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[1]) then return 1 end
  if not comp(x, ary[num]) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid]) then
      min = mid
    else
      max = mid
    end
  end
  return max
end


local n, k = io.read("*n", "*n")
local s = 0
local t = {}
for i = 1, k do
  t[i] = io.read("*n")
  s = s + t[i]
end
local v = {s}
for i = k + 1, n do
  t[i] = io.read("*n")
  s = s + t[i] - t[i - k]
  v[i - k + 1] = s
end
table.sort(v)
local q = io.read("*n")
for iq = 1, q do
  local x = io.read("*n")
  local ub = upper_bound(v, x)
  print(ub - 1)
end
0