結果
| 問題 |
No.1012 荷物収集
|
| コンテスト | |
| ユーザー |
neterukun
|
| 提出日時 | 2020-03-20 23:28:07 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,157 bytes |
| コンパイル時間 | 2,594 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 103,580 KB |
| 最終ジャッジ日時 | 2024-12-15 18:30:20 |
| 合計ジャッジ時間 | 13,087 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 11 WA * 30 |
ソースコード
n, q = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]
query = list(map(int, input().split()))
info = sorted(info)
ans = [0] * q
ind = 0
weight = 0
for i in range(q):
tmp = 0
pos = query[i]
if i - 1 >= 0:
prv_pos = query[i - 1]
else:
prv_pos = pos
while True:
if ind >= n:
break
x, w = info[ind]
if x <= pos:
tmp += w
ans[i] += w * (pos - x)
ind += 1
else:
break
if i - 1 >= 0:
ans[i] += (pos - prv_pos) * weight + ans[i - 1]
weight += tmp
ans2 = [0] * q
ind = n - 1
weight = 0
for i in range(q)[::-1]:
tmp = 0
pos = query[i]
if i + 1 < q:
prv_pos = query[i + 1]
else:
prv_pos = pos
while True:
if ind < 0:
break
x, w = info[ind]
if x >= pos:
tmp += w
ans2[i] += w * abs(pos - x)
ind -= 1
else:
break
if i + 1 < q:
ans2[i] += abs(pos - prv_pos) * weight + ans2[i + 1]
weight += tmp
for i in range(q):
print(ans[i] + ans2[i])
neterukun