結果

問題 No.1012 荷物収集
ユーザー H3PO4H3PO4
提出日時 2021-08-24 09:17:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 735 ms / 2,000 ms
コード長 744 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 51,592 KB
最終ジャッジ日時 2024-04-26 13:07:21
合計ジャッジ時間 18,050 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 30 ms
10,624 KB
testcase_03 AC 29 ms
10,752 KB
testcase_04 AC 481 ms
51,460 KB
testcase_05 AC 478 ms
51,460 KB
testcase_06 AC 489 ms
51,592 KB
testcase_07 AC 482 ms
51,584 KB
testcase_08 AC 480 ms
51,460 KB
testcase_09 AC 481 ms
51,460 KB
testcase_10 AC 477 ms
51,456 KB
testcase_11 AC 472 ms
51,456 KB
testcase_12 AC 477 ms
51,424 KB
testcase_13 AC 479 ms
51,460 KB
testcase_14 AC 29 ms
10,880 KB
testcase_15 AC 31 ms
10,880 KB
testcase_16 AC 30 ms
10,880 KB
testcase_17 AC 31 ms
10,880 KB
testcase_18 AC 31 ms
11,008 KB
testcase_19 AC 29 ms
10,880 KB
testcase_20 AC 30 ms
10,880 KB
testcase_21 AC 30 ms
10,752 KB
testcase_22 AC 32 ms
10,880 KB
testcase_23 AC 29 ms
10,880 KB
testcase_24 AC 453 ms
35,980 KB
testcase_25 AC 629 ms
44,056 KB
testcase_26 AC 340 ms
29,220 KB
testcase_27 AC 96 ms
15,104 KB
testcase_28 AC 603 ms
43,408 KB
testcase_29 AC 418 ms
31,488 KB
testcase_30 AC 648 ms
44,456 KB
testcase_31 AC 224 ms
24,724 KB
testcase_32 AC 202 ms
22,020 KB
testcase_33 AC 336 ms
28,476 KB
testcase_34 AC 357 ms
29,768 KB
testcase_35 AC 568 ms
38,720 KB
testcase_36 AC 329 ms
28,336 KB
testcase_37 AC 412 ms
29,928 KB
testcase_38 AC 505 ms
37,268 KB
testcase_39 AC 220 ms
22,996 KB
testcase_40 AC 253 ms
24,960 KB
testcase_41 AC 735 ms
47,476 KB
testcase_42 AC 311 ms
28,324 KB
testcase_43 AC 449 ms
34,980 KB
testcase_44 AC 28 ms
10,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline

N, Q = map(int, input().split())
freight = [tuple(map(int, input().split())) for _ in range(N)]
X = tuple(map(int, input().split()))

cost_x0 = sum(x * w for x, w in freight)
queries = []
for x, w in freight:
    queries.append((x, 1, w))
for i, x in enumerate(X):
    queries.append((x, 2, i))

queries.sort()
cost = cost_x0
cur_idx = 0
left_weight, right_weight = 0, sum(w for _, w in freight)
ans = [0] * Q
for q in queries:
    x = q[0]
    cost += left_weight * (x - cur_idx)
    cost -= right_weight * (x - cur_idx)
    cur_idx = x
    if q[1] == 1:
        left_weight += q[2]
        right_weight -= q[2]
    else:
        # assert q[1] == 2
        ans[q[2]] = cost
print(*ans, sep='\n')
0