結果

問題 No.1012 荷物収集
コンテスト
ユーザー takakin
提出日時 2020-03-22 20:03:40
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 411 ms / 2,000 ms
+ 747µs
コード長 500 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 57 ms
コンパイル使用メモリ 15,232 KB
実行使用メモリ 44,440 KB
最終ジャッジ日時 2026-10-07 23:09:41
合計ジャッジ時間 13,340 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input=lambda: sys.stdin.readline().rstrip()
n,q=map(int,input().split())
X,XW=[],[]
tot_xw,tot_w=0,0
for _ in range(n):
  x,w=map(int,input().split())
  tot_xw+=x*w
  tot_w+=w
  XW.append((x,w))
  X.append(x)
XW.sort(key=lambda x:x[0])
X.sort()
A,B=[0]*(n+1),[0]*(n+1)
A[0]=-tot_w
B[0]=tot_xw
for i in range(n):
  A[i+1]=A[i]+2*XW[i][1]
  B[i+1]=B[i]-2*XW[i][0]*XW[i][1]

import bisect
Q=[int(i) for i in input().split()]
for q in Q:
  ind=bisect.bisect_left(X,q)
  print(A[ind]*q+B[ind])
0