結果

問題 No.1012 荷物収集
ユーザー tamatotamato
提出日時 2020-03-20 21:49:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 453 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 109,608 KB
最終ジャッジ日時 2024-05-08 21:45:17
合計ジャッジ時間 12,149 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,096 KB
testcase_01 AC 39 ms
52,480 KB
testcase_02 AC 39 ms
51,712 KB
testcase_03 AC 38 ms
51,968 KB
testcase_04 AC 190 ms
108,736 KB
testcase_05 AC 189 ms
108,612 KB
testcase_06 AC 191 ms
108,996 KB
testcase_07 AC 193 ms
108,608 KB
testcase_08 AC 189 ms
108,484 KB
testcase_09 AC 191 ms
108,988 KB
testcase_10 AC 191 ms
108,856 KB
testcase_11 AC 193 ms
108,604 KB
testcase_12 AC 192 ms
108,604 KB
testcase_13 AC 191 ms
108,604 KB
testcase_14 AC 41 ms
53,248 KB
testcase_15 AC 52 ms
62,976 KB
testcase_16 AC 43 ms
53,376 KB
testcase_17 AC 53 ms
62,848 KB
testcase_18 AC 47 ms
59,904 KB
testcase_19 AC 41 ms
52,480 KB
testcase_20 AC 41 ms
52,608 KB
testcase_21 AC 42 ms
53,632 KB
testcase_22 AC 44 ms
54,016 KB
testcase_23 AC 42 ms
53,632 KB
testcase_24 AC 294 ms
107,904 KB
testcase_25 AC 391 ms
108,492 KB
testcase_26 AC 199 ms
87,296 KB
testcase_27 AC 92 ms
77,972 KB
testcase_28 AC 368 ms
104,700 KB
testcase_29 AC 200 ms
85,120 KB
testcase_30 AC 385 ms
102,300 KB
testcase_31 AC 188 ms
91,392 KB
testcase_32 AC 163 ms
86,656 KB
testcase_33 AC 236 ms
94,868 KB
testcase_34 AC 258 ms
97,148 KB
testcase_35 AC 292 ms
97,000 KB
testcase_36 AC 247 ms
99,484 KB
testcase_37 AC 193 ms
84,660 KB
testcase_38 AC 299 ms
107,540 KB
testcase_39 AC 153 ms
82,996 KB
testcase_40 AC 182 ms
87,400 KB
testcase_41 AC 453 ms
109,608 KB
testcase_42 AC 233 ms
97,112 KB
testcase_43 AC 271 ms
100,736 KB
testcase_44 AC 39 ms
52,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.buffer.readline

    N, Q = map(int, input().split())
    XW = []
    for _ in range(N):
        x, w = map(int, input().split())
        XW.append((x, w))
    Q = list(map(int, input().split()))
    for x in Q:
        XW.append((x, 0))
    XW.sort(key=lambda l: l[0])

    L = len(XW)
    ans = {}
    dp_left = [0] * L
    dp_right = [0] * L
    S = 0
    x_prev = XW[0][0]
    for i in range(L):
        x, w = XW[i]
        dp_left[i] = dp_left[i-1] + (x - x_prev) * S
        S += w
        x_prev = x
        if w == 0:
            ans[x] = dp_left[i]
    S = 0
    x_prev = XW[-1][0]
    for i in range(L):
        x, w = XW[-i-1]
        if i:
            dp_right[-i-1] = dp_right[-i] + (x_prev - x) * S
        else:
            dp_right[-1] = 0
        S += w
        x_prev = x
        if w == 0:
            ans[x] += dp_right[-i-1]

    for x in Q:
        print(ans[x])


if __name__ == '__main__':
    main()
0