結果

問題 No.1012 荷物収集
ユーザー takakin
提出日時 2020-03-22 20:03:40
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 687 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 44,108 KB
最終ジャッジ日時 2024-12-25 21:24:00
合計ジャッジ時間 18,671 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

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