結果

問題 No.1012 荷物収集
ユーザー brthyyjpbrthyyjp
提出日時 2020-03-25 07:24:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 511 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 115,868 KB
最終ジャッジ日時 2023-08-30 09:25:37
合計ジャッジ時間 16,547 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,344 KB
testcase_01 AC 73 ms
71,308 KB
testcase_02 AC 72 ms
71,400 KB
testcase_03 AC 71 ms
71,476 KB
testcase_04 AC 207 ms
115,868 KB
testcase_05 AC 205 ms
115,720 KB
testcase_06 AC 204 ms
115,868 KB
testcase_07 AC 203 ms
115,748 KB
testcase_08 AC 202 ms
115,748 KB
testcase_09 AC 206 ms
115,816 KB
testcase_10 AC 204 ms
115,664 KB
testcase_11 AC 205 ms
115,804 KB
testcase_12 AC 206 ms
115,552 KB
testcase_13 AC 204 ms
115,732 KB
testcase_14 AC 77 ms
75,344 KB
testcase_15 AC 89 ms
75,944 KB
testcase_16 AC 82 ms
75,396 KB
testcase_17 AC 87 ms
76,060 KB
testcase_18 AC 85 ms
75,836 KB
testcase_19 AC 79 ms
75,308 KB
testcase_20 AC 74 ms
71,448 KB
testcase_21 AC 81 ms
75,492 KB
testcase_22 AC 83 ms
75,452 KB
testcase_23 AC 83 ms
75,572 KB
testcase_24 AC 317 ms
95,140 KB
testcase_25 AC 433 ms
100,248 KB
testcase_26 AC 337 ms
95,508 KB
testcase_27 AC 154 ms
81,076 KB
testcase_28 AC 434 ms
101,572 KB
testcase_29 AC 402 ms
97,976 KB
testcase_30 AC 473 ms
108,456 KB
testcase_31 AC 155 ms
86,588 KB
testcase_32 AC 184 ms
85,068 KB
testcase_33 AC 204 ms
89,416 KB
testcase_34 AC 199 ms
92,956 KB
testcase_35 AC 396 ms
99,184 KB
testcase_36 AC 170 ms
89,300 KB
testcase_37 AC 376 ms
101,368 KB
testcase_38 AC 334 ms
97,944 KB
testcase_39 AC 222 ms
86,108 KB
testcase_40 AC 222 ms
85,392 KB
testcase_41 AC 511 ms
108,908 KB
testcase_42 AC 261 ms
87,200 KB
testcase_43 AC 371 ms
95,792 KB
testcase_44 AC 77 ms
71,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

n, q = map(int, input().split())
L = [[0, 0] for _ in range(n)]
xs = [0]*n
for i in range(n):
    x, w = map(int, input().split())
    L[i][0] = x
    L[i][1] = w
    xs[i] = x
X = list(map(int, input().split()))

L.sort()
xs.sort()

ws = [0]*n
wxs = [0]*n
for i in range(n):
    x, w = L[i]
    ws[i] = w
    wxs[i] = x*w

cumw = [0]+ws
cumxw = [0]+wxs
from itertools import accumulate
cumw = list(accumulate(cumw))
cumxw = list(accumulate(cumxw))

import bisect
for x in X:
    k = bisect.bisect_right(xs, x)
    if k == 0:
        ans = cumxw[-1] - cumw[-1]*x
    elif k == n:
        ans = -cumxw[-1] + cumw[-1]*x
    else:
        ans = x*(cumw[-1]-2*(cumw[-1]-cumw[k]))+(cumxw[-1]-2*cumxw[k])
    print(ans)
0