結果

問題 No.1012 荷物収集
ユーザー maspy
提出日時 2020-03-21 00:02:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,106 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 80,792 KB
最終ジャッジ日時 2024-12-15 21:45:35
合計ジャッジ時間 39,854 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N, Q = map(int, readline().split())
event = []
S = 0
coef = 0
for _ in range(N):
    x, w = map(int, readline().split())
    event.append((x, w, 1))
    S += x * w
    coef -= w

X = map(int, read().split())
for i, x in enumerate(X):
    event.append((x, i, 2))

event.sort()

answer = [0] * Q
X = 0

for x, w, t in event:
    if t == 1:
        S += (x - X) * coef
        coef += 2 * w
        X = x
    else:
        i = w
        answer[i] = coef * (x - X) + S

print('\n'.join(map(str, answer)))
0