結果

問題 No.1012 荷物収集
ユーザー 👑 obakyanobakyan
提出日時 2020-03-20 22:20:04
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 682 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 5,296 KB
実行使用メモリ 39,032 KB
最終ジャッジ日時 2023-08-21 17:05:42
合計ジャッジ時間 16,183 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 515 ms
38,896 KB
testcase_05 AC 513 ms
38,884 KB
testcase_06 AC 516 ms
39,000 KB
testcase_07 AC 510 ms
39,032 KB
testcase_08 AC 513 ms
39,028 KB
testcase_09 AC 513 ms
38,904 KB
testcase_10 AC 511 ms
38,892 KB
testcase_11 AC 511 ms
38,820 KB
testcase_12 AC 512 ms
38,832 KB
testcase_13 AC 514 ms
38,992 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 495 ms
28,840 KB
testcase_25 AC 632 ms
37,020 KB
testcase_26 AC 192 ms
17,020 KB
testcase_27 AC 35 ms
5,524 KB
testcase_28 AC 563 ms
34,208 KB
testcase_29 AC 116 ms
9,860 KB
testcase_30 AC 562 ms
33,256 KB
testcase_31 AC 385 ms
24,988 KB
testcase_32 AC 189 ms
14,888 KB
testcase_33 AC 416 ms
26,192 KB
testcase_34 AC 480 ms
23,992 KB
testcase_35 AC 446 ms
28,700 KB
testcase_36 AC 505 ms
29,676 KB
testcase_37 AC 121 ms
10,992 KB
testcase_38 AC 500 ms
29,096 KB
testcase_39 AC 165 ms
12,812 KB
testcase_40 AC 241 ms
16,776 KB
testcase_41 AC 682 ms
38,156 KB
testcase_42 AC 308 ms
21,504 KB
testcase_43 AC 387 ms
23,772 KB
testcase_44 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl = math.floor

local function comp(a, b)
  return a[2] < b
end

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

local n, q = io.read("*n", "*n")
local xs, ws = {}, {}
for i = 1, n do
  xs[i], ws[i] = io.read("*n", "*n")
end
local qs = {}
for i = 1, q do
  qs[i] = {}
  qs[i][1] = i
  qs[i][2] = io.read("*n")
  qs[i][3] = 0LL -- sum of xi * wi
  qs[i][4] = 0LL -- sum of wi (for multiplied by Xi)
end
qs[q + 1] = {q + 1, 1000000007, 0LL, 0LL}
table.sort(qs, function(a, b) return a[2] < b[2] end)
for i = 1, n do
  local x, w = 0LL + xs[i], 0LL + ws[i]
  local pos = lower_bound(qs, x)
  qs[1][3] = qs[1][3] + x * w
  qs[pos][3] = qs[pos][3] - 2LL * x * w
  qs[1][4] = qs[1][4] - w
  qs[pos][4] = qs[pos][4] + 2LL * w
end
for i = 2, q do
  qs[i][3] = qs[i][3] + qs[i - 1][3]
  qs[i][4] = qs[i][4] + qs[i - 1][4]
end
table.sort(qs, function(a, b) return a[1] < b[1] end)
for i = 1, q do
  local v = qs[i][3] + qs[i][2] * qs[i][4]
  local str = tostring(v):gsub("LL", "")
  print(str)
end
0