結果
問題 |
No.1093 区間の和 / Sum of Range
|
ユーザー |
👑 |
提出日時 | 2020-11-26 09:40:00 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 104 ms / 2,000 ms |
コード長 | 796 bytes |
コンパイル時間 | 120 ms |
コンパイル使用メモリ | 6,816 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-23 20:43:34 |
合計ジャッジ時間 | 4,038 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 36 |
ソースコード
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