結果

問題 No.1012 荷物収集
コンテスト
ユーザー takakin
提出日時 2020-03-22 20:03:40
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 832 ms / 2,000 ms
コード長 500 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 598 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 46,680 KB
最終ジャッジ日時 2026-05-31 14:08:25
合計ジャッジ時間 19,848 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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