結果

問題 No.1012 荷物収集
ユーザー stngstng
提出日時 2022-08-17 23:03:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 869 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 115,772 KB
最終ジャッジ日時 2024-04-15 10:41:51
合計ジャッジ時間 16,699 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
n,q = map(int,input().split())
xw = [[int(i) for i in input().split()] for j in range(n)]
x = [int(i) for i in input().split()]

xx = []
for i in range(q):
    xx.append([x[i],i])
xx.sort()

x.sort()
xw.sort()
pos = []
wei = []
for i in range(n):
    pos.append(xw[i][0])
    wei.append(xw[i][1])

rw = [0]*(n+1)
for i in range(n):
    rw[i+1] = rw[i]+wei[i]

ali = [0]*q

ans = 0
for i in range(n):
    ans += abs(x[0]-pos[i])*wei[i]
ali[xx[0][1]] = ans

print(ans)

for i in range(q-1):
    bidx = bisect.bisect_right(pos,x[i])
    aidx = bisect.bisect_left(pos,x[i+1])
    #print(bidx,aidx,rw)
    ans += (x[i+1]-x[i])*(rw[bidx]-rw[0])
    ans -= (x[i+1]-x[i])*(rw[n]-rw[aidx])
    for j in range(bidx,aidx):
        ans -= abs(x[i]-pos[j])*wei[j]
        ans += abs(x[i+1]-pos[j])*wei[j]
    #print(ans)
    ali[xx[i+1][1]] = ans

print(*ali,sep="\n")
0