結果

問題 No.1012 荷物収集
ユーザー stngstng
提出日時 2022-08-17 23:03:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 843 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,204 KB
実行使用メモリ 115,504 KB
最終ジャッジ日時 2024-04-15 10:42:22
合計ジャッジ時間 17,432 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,480 KB
testcase_01 AC 40 ms
52,608 KB
testcase_02 AC 40 ms
52,224 KB
testcase_03 AC 43 ms
52,460 KB
testcase_04 AC 316 ms
115,380 KB
testcase_05 AC 309 ms
115,504 KB
testcase_06 AC 299 ms
115,124 KB
testcase_07 AC 303 ms
115,260 KB
testcase_08 AC 299 ms
115,132 KB
testcase_09 AC 298 ms
115,388 KB
testcase_10 AC 309 ms
115,384 KB
testcase_11 AC 300 ms
115,132 KB
testcase_12 AC 298 ms
115,388 KB
testcase_13 AC 304 ms
115,376 KB
testcase_14 AC 52 ms
60,288 KB
testcase_15 AC 64 ms
66,816 KB
testcase_16 AC 57 ms
63,232 KB
testcase_17 AC 65 ms
66,944 KB
testcase_18 AC 61 ms
65,536 KB
testcase_19 AC 49 ms
60,032 KB
testcase_20 AC 47 ms
54,912 KB
testcase_21 AC 56 ms
62,848 KB
testcase_22 AC 59 ms
64,512 KB
testcase_23 AC 56 ms
62,464 KB
testcase_24 AC 587 ms
104,136 KB
testcase_25 AC 783 ms
104,380 KB
testcase_26 AC 429 ms
98,188 KB
testcase_27 AC 175 ms
80,768 KB
testcase_28 AC 731 ms
111,452 KB
testcase_29 AC 474 ms
99,504 KB
testcase_30 AC 749 ms
106,592 KB
testcase_31 AC 365 ms
94,192 KB
testcase_32 AC 293 ms
86,080 KB
testcase_33 AC 429 ms
96,180 KB
testcase_34 AC 478 ms
90,668 KB
testcase_35 AC 649 ms
100,884 KB
testcase_36 AC 450 ms
97,408 KB
testcase_37 AC 448 ms
100,480 KB
testcase_38 AC 613 ms
100,652 KB
testcase_39 AC 317 ms
88,192 KB
testcase_40 AC 365 ms
88,832 KB
testcase_41 AC 843 ms
109,080 KB
testcase_42 AC 440 ms
93,580 KB
testcase_43 AC 548 ms
97,012 KB
testcase_44 AC 43 ms
52,352 KB
権限があれば一括ダウンロードができます

ソースコード

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

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