結果

問題 No.1012 荷物収集
ユーザー brthyyjpbrthyyjp
提出日時 2020-03-20 23:20:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,139 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 56,800 KB
最終ジャッジ日時 2024-05-09 05:41:05
合計ジャッジ時間 4,673 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
17,952 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 30 ms
10,880 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())
    L = []
    xs = []
    for i in range(n):
        x, w = map(int, input().split())
        L.append([x, w])
        xs.append(x)
    X = list(map(int, input().split()))
    L.sort()
    xs.sort()

    Wl = [0]*n
    Wr = [0]*n
    wsl = [0]*n
    wsr = [0]*n
    for i in range(n):
        if i == 0:
            wsl[i] = L[i][1]
        else:
            wsl[i] = wsl[i-1] + L[i][1]
            Wl[i] = wsl[i-1]*(xs[i]-xs[i-1]) + Wl[i-1]

    for i in reversed(range(n)):
        if i == n-1:
            wsr[i] = L[i][1]
        else:
            j = n-1-i
            wsr[i] = wsr[i+1] + L[i][1]
            Wr[i] = wsr[i+1]*(xs[i+1]-xs[i]) + Wr[i+1]
    #print(Wl)
    #print(Wr)
    import bisect
    for x in X:
        if x < min(xs):
            ans = wsr[0]*(xs[0]-x)+Wr[0]
        elif x >= max(xs):
            ans = wsl[-1]*(x-xs[-1])+Wl[-1]
        else:
            id = bisect.bisect_right(xs, x)
            ans = wsl[id-1]*(x-xs[id-1])+Wl[id-1]+ wsr[id]*(xs[id]-x)+Wr[id]
        print(ans)

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