結果
問題 | No.1012 荷物収集 |
ユーザー | convexineq |
提出日時 | 2020-03-20 22:04:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 307 ms / 2,000 ms |
コード長 | 783 bytes |
コンパイル時間 | 339 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 106,492 KB |
最終ジャッジ日時 | 2024-12-15 05:56:25 |
合計ジャッジ時間 | 9,398 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
ソースコード
# coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline read = sys.stdin.read n,Q = [int(i) for i in readline().split()] xw = [[int(i) for i in readline().split()] for _ in range(n)] qs = [int(i) for i in readline().split()] xw.sort(key = lambda x:x[0]) c = -sum(xwi[1] for xwi in xw) xs = [xwi[0] for xwi in xw] + [10**10] x0 = xw[0][0] v = sum((x-x0)*w for x,w in xw) coeff = [c] val = [] for i,(x,w) in enumerate(xw): c += 2*w coeff.append(c) val.append(v) v += c*(xs[i+1]-xs[i]) xs.pop() v = val[-1] from bisect import bisect_left for q in qs: idx = bisect_left(xs,q) if idx < n: print(val[idx]-coeff[idx]*(xs[idx]-q)) else: print(v+c*(q-xs[-1]))