結果
問題 | No.2408 Lakes and Fish |
ユーザー |
👑 |
提出日時 | 2023-08-11 21:28:48 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 873 bytes |
コンパイル時間 | 289 ms |
コンパイル使用メモリ | 7,080 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 15:26:04 |
合計ジャッジ時間 | 2,993 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
local mfl = math.floorlocal function comp(a, b)return a < bendlocal function lower_bound(ary, x)local num = #aryif num == 0 then return 1 endif not comp(ary[1], x) then return 1 endif comp(ary[num], x) then return num + 1 endlocal min, max = 1, numwhile 1 < max - min dolocal mid = mfl((min + max) / 2)if comp(ary[mid], x) thenmin = midelsemax = midendendreturn maxendlocal n, m = io.read("*n", "*n")local l = {}for i = 1, n dol[i] = io.read("*n")endlocal ans = 0for i = 1, m dolocal f, b, w = io.read("*n", "*n", "*n")local lb = lower_bound(l, f)local len = 0if lb == 1 thenlen = l[1] - felseif n < lb thenlen = f - l[n]elselen = math.min(l[lb] - f, f - l[lb - 1])endans = ans + math.max(b, w - len)endans = tostring(ans * 1LL):gsub("LL", "")print(ans)