結果

問題 No.1012 荷物収集
ユーザー stngstng
提出日時 2022-08-17 23:03:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 830 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 82,020 KB
実行使用メモリ 117,052 KB
最終ジャッジ日時 2024-04-15 10:42:47
合計ジャッジ時間 17,203 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,300 KB
testcase_01 AC 42 ms
52,352 KB
testcase_02 AC 40 ms
52,352 KB
testcase_03 AC 42 ms
52,708 KB
testcase_04 AC 298 ms
117,052 KB
testcase_05 AC 301 ms
116,668 KB
testcase_06 AC 297 ms
116,880 KB
testcase_07 AC 294 ms
116,924 KB
testcase_08 AC 303 ms
116,784 KB
testcase_09 AC 300 ms
117,052 KB
testcase_10 AC 300 ms
116,800 KB
testcase_11 AC 305 ms
116,540 KB
testcase_12 AC 304 ms
116,668 KB
testcase_13 AC 294 ms
116,932 KB
testcase_14 AC 52 ms
60,928 KB
testcase_15 AC 59 ms
65,792 KB
testcase_16 AC 55 ms
62,336 KB
testcase_17 AC 60 ms
65,536 KB
testcase_18 AC 58 ms
64,384 KB
testcase_19 AC 52 ms
60,672 KB
testcase_20 AC 59 ms
60,544 KB
testcase_21 AC 56 ms
61,696 KB
testcase_22 AC 56 ms
62,592 KB
testcase_23 AC 55 ms
61,056 KB
testcase_24 AC 573 ms
102,984 KB
testcase_25 AC 740 ms
104,492 KB
testcase_26 AC 435 ms
97,792 KB
testcase_27 AC 171 ms
80,620 KB
testcase_28 AC 730 ms
112,092 KB
testcase_29 AC 473 ms
99,200 KB
testcase_30 AC 746 ms
106,640 KB
testcase_31 AC 363 ms
94,072 KB
testcase_32 AC 306 ms
85,888 KB
testcase_33 AC 428 ms
96,160 KB
testcase_34 AC 476 ms
90,640 KB
testcase_35 AC 652 ms
101,016 KB
testcase_36 AC 448 ms
97,280 KB
testcase_37 AC 455 ms
99,840 KB
testcase_38 AC 608 ms
98,352 KB
testcase_39 AC 318 ms
88,164 KB
testcase_40 AC 366 ms
88,832 KB
testcase_41 AC 830 ms
109,080 KB
testcase_42 AC 415 ms
92,800 KB
testcase_43 AC 536 ms
98,308 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_right(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