結果

問題 No.1012 荷物収集
ユーザー ああいいああいい
提出日時 2022-02-19 18:53:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 105,720 KB
最終ジャッジ日時 2023-09-11 20:51:01
合計ジャッジ時間 15,794 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,204 KB
testcase_01 AC 71 ms
71,348 KB
testcase_02 AC 71 ms
71,584 KB
testcase_03 AC 72 ms
71,516 KB
testcase_04 AC 231 ms
105,580 KB
testcase_05 AC 219 ms
105,476 KB
testcase_06 AC 222 ms
105,720 KB
testcase_07 AC 223 ms
105,608 KB
testcase_08 AC 223 ms
105,636 KB
testcase_09 AC 224 ms
105,596 KB
testcase_10 AC 223 ms
105,624 KB
testcase_11 AC 222 ms
105,596 KB
testcase_12 AC 222 ms
105,476 KB
testcase_13 AC 225 ms
105,596 KB
testcase_14 AC 77 ms
71,288 KB
testcase_15 AC 84 ms
75,808 KB
testcase_16 AC 78 ms
71,352 KB
testcase_17 AC 83 ms
75,956 KB
testcase_18 AC 81 ms
75,312 KB
testcase_19 AC 77 ms
71,440 KB
testcase_20 AC 80 ms
71,464 KB
testcase_21 AC 80 ms
71,508 KB
testcase_22 AC 80 ms
71,380 KB
testcase_23 AC 79 ms
71,292 KB
testcase_24 AC 316 ms
94,896 KB
testcase_25 AC 374 ms
99,864 KB
testcase_26 AC 263 ms
88,468 KB
testcase_27 AC 145 ms
79,328 KB
testcase_28 AC 350 ms
92,580 KB
testcase_29 AC 269 ms
85,168 KB
testcase_30 AC 368 ms
99,548 KB
testcase_31 AC 211 ms
95,240 KB
testcase_32 AC 196 ms
84,404 KB
testcase_33 AC 249 ms
93,564 KB
testcase_34 AC 253 ms
93,200 KB
testcase_35 AC 316 ms
93,736 KB
testcase_36 AC 240 ms
97,920 KB
testcase_37 AC 261 ms
84,060 KB
testcase_38 AC 314 ms
95,372 KB
testcase_39 AC 198 ms
82,464 KB
testcase_40 AC 217 ms
86,140 KB
testcase_41 AC 393 ms
105,384 KB
testcase_42 AC 259 ms
90,412 KB
testcase_43 AC 289 ms
92,528 KB
testcase_44 AC 74 ms
71,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,Q = map(int,input().split())
l = []
for _ in range(N):
    x,w = map(int,input().split())
    l.append((x,w))
l.sort(key = lambda x:x[0])
X = list(map(int,input().split()))
X = [(X[i],i) for i in range(Q)]
ans = [0] * Q
X.sort(key = lambda s:s[0])
hidari = [0] * (N+1)
migi = [0] * (N+1)
for i in range(N):
    hidari[i+1] = hidari[i] + l[i][1]
for i in range(N-1,-1,-1):
    migi[i] = migi[i+1] + l[i][1]
a = 0
x = X[0][0]
index = X[0][1]
for i in range(N):
    s,w = l[i]
    a += abs(s-x) * w
ans[index] = a
left = 0
now = x
for i in range(1,Q):
    x,index = X[i]
    while left < N and l[left][0] <= now:
        left += 1
    delta = x - now
    a += delta * hidari[left]
    right = left
    while right < N and l[right][0] <= x:
        a -= (l[right][0] - now) * l[right][1]
        a += (x - l[right][0]) * l[right][1]
        right += 1
    a -= delta * migi[right]
    ans[index] = a
    now = x
print(*ans,sep="\n")
0