結果
| 問題 |
No.1012 荷物収集
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-24 09:17:09 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 700 ms / 2,000 ms |
| コード長 | 744 bytes |
| コンパイル時間 | 136 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 51,588 KB |
| 最終ジャッジ日時 | 2024-11-14 00:41:25 |
| 合計ジャッジ時間 | 17,726 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
ソースコード
import sys
input = sys.stdin.buffer.readline
N, Q = map(int, input().split())
freight = [tuple(map(int, input().split())) for _ in range(N)]
X = tuple(map(int, input().split()))
cost_x0 = sum(x * w for x, w in freight)
queries = []
for x, w in freight:
queries.append((x, 1, w))
for i, x in enumerate(X):
queries.append((x, 2, i))
queries.sort()
cost = cost_x0
cur_idx = 0
left_weight, right_weight = 0, sum(w for _, w in freight)
ans = [0] * Q
for q in queries:
x = q[0]
cost += left_weight * (x - cur_idx)
cost -= right_weight * (x - cur_idx)
cur_idx = x
if q[1] == 1:
left_weight += q[2]
right_weight -= q[2]
else:
# assert q[1] == 2
ans[q[2]] = cost
print(*ans, sep='\n')