結果

問題 No.1012 荷物収集
ユーザー 👑 tamatotamato
提出日時 2020-03-20 21:49:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 442 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 110,000 KB
最終ジャッジ日時 2023-08-21 16:15:12
合計ジャッジ時間 12,601 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,444 KB
testcase_01 AC 75 ms
71,232 KB
testcase_02 AC 74 ms
71,428 KB
testcase_03 AC 80 ms
71,128 KB
testcase_04 AC 218 ms
109,864 KB
testcase_05 AC 215 ms
109,772 KB
testcase_06 AC 217 ms
109,832 KB
testcase_07 AC 217 ms
109,800 KB
testcase_08 AC 217 ms
109,856 KB
testcase_09 AC 221 ms
109,768 KB
testcase_10 AC 216 ms
109,804 KB
testcase_11 AC 214 ms
110,000 KB
testcase_12 AC 215 ms
109,804 KB
testcase_13 AC 214 ms
109,912 KB
testcase_14 AC 78 ms
71,392 KB
testcase_15 AC 97 ms
76,396 KB
testcase_16 AC 78 ms
71,260 KB
testcase_17 AC 88 ms
76,296 KB
testcase_18 AC 82 ms
75,448 KB
testcase_19 AC 75 ms
71,280 KB
testcase_20 AC 74 ms
71,496 KB
testcase_21 AC 77 ms
71,432 KB
testcase_22 AC 80 ms
71,192 KB
testcase_23 AC 76 ms
70,984 KB
testcase_24 AC 322 ms
108,104 KB
testcase_25 AC 422 ms
108,808 KB
testcase_26 AC 232 ms
88,260 KB
testcase_27 AC 124 ms
79,024 KB
testcase_28 AC 385 ms
103,372 KB
testcase_29 AC 225 ms
85,844 KB
testcase_30 AC 397 ms
102,288 KB
testcase_31 AC 232 ms
96,028 KB
testcase_32 AC 182 ms
84,832 KB
testcase_33 AC 256 ms
97,088 KB
testcase_34 AC 270 ms
98,188 KB
testcase_35 AC 318 ms
98,108 KB
testcase_36 AC 272 ms
98,736 KB
testcase_37 AC 222 ms
85,728 KB
testcase_38 AC 329 ms
108,912 KB
testcase_39 AC 210 ms
86,732 KB
testcase_40 AC 212 ms
92,272 KB
testcase_41 AC 442 ms
108,604 KB
testcase_42 AC 253 ms
100,332 KB
testcase_43 AC 300 ms
101,672 KB
testcase_44 AC 75 ms
71,024 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