結果

問題 No.1012 荷物収集
ユーザー nagitaosunagitaosu
提出日時 2020-03-20 23:03:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 467 ms / 2,000 ms
コード長 938 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 86,348 KB
実行使用メモリ 125,640 KB
最終ジャッジ日時 2023-08-21 18:31:44
合計ジャッジ時間 13,941 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,544 KB
testcase_01 AC 73 ms
71,452 KB
testcase_02 AC 73 ms
71,352 KB
testcase_03 AC 73 ms
71,228 KB
testcase_04 AC 237 ms
125,376 KB
testcase_05 AC 226 ms
125,532 KB
testcase_06 AC 224 ms
125,640 KB
testcase_07 AC 224 ms
125,408 KB
testcase_08 AC 227 ms
125,588 KB
testcase_09 AC 225 ms
125,436 KB
testcase_10 AC 223 ms
125,180 KB
testcase_11 AC 222 ms
125,472 KB
testcase_12 AC 226 ms
125,484 KB
testcase_13 AC 224 ms
125,508 KB
testcase_14 AC 79 ms
75,180 KB
testcase_15 AC 89 ms
75,884 KB
testcase_16 AC 81 ms
75,372 KB
testcase_17 AC 87 ms
76,012 KB
testcase_18 AC 84 ms
75,808 KB
testcase_19 AC 76 ms
75,380 KB
testcase_20 AC 75 ms
71,028 KB
testcase_21 AC 81 ms
75,440 KB
testcase_22 AC 84 ms
75,232 KB
testcase_23 AC 82 ms
75,408 KB
testcase_24 AC 306 ms
93,828 KB
testcase_25 AC 412 ms
107,760 KB
testcase_26 AC 321 ms
95,164 KB
testcase_27 AC 160 ms
80,292 KB
testcase_28 AC 418 ms
107,476 KB
testcase_29 AC 386 ms
117,392 KB
testcase_30 AC 447 ms
112,884 KB
testcase_31 AC 168 ms
85,548 KB
testcase_32 AC 192 ms
84,132 KB
testcase_33 AC 211 ms
85,724 KB
testcase_34 AC 203 ms
85,728 KB
testcase_35 AC 382 ms
103,124 KB
testcase_36 AC 176 ms
85,536 KB
testcase_37 AC 363 ms
100,824 KB
testcase_38 AC 337 ms
100,884 KB
testcase_39 AC 221 ms
89,144 KB
testcase_40 AC 224 ms
86,964 KB
testcase_41 AC 467 ms
122,272 KB
testcase_42 AC 255 ms
92,892 KB
testcase_43 AC 346 ms
106,520 KB
testcase_44 AC 75 ms
71,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import bisect

n, q = map(int, input().split())
places = []
r_x = [0] * n
r_1 = [0] * n
l_x = [0] * n
l_1 = [0] * n
xw = []
for i in range(n):
    x, w = map(int, input().split())
    xw.append((x, w))
xw.sort()

for i, (x, w) in enumerate(xw):
    places.append(x)
    r_x[i] = w
    l_x[i] = -w
    r_1[i] = -(x * w)
    l_1[i] = x * w

r_x_cum = [0]
r_1_cum = [0]
for item in r_x:
    r_x_cum.append(r_x_cum[-1] + item)
for item in r_1:
    r_1_cum.append(r_1_cum[-1] + item)
l_x_cum = [0]
l_1_cum = [0]
for item in l_x[::-1]:
    l_x_cum.append(l_x_cum[-1] + item)
for item in l_1[::-1]:
    l_1_cum.append(l_1_cum[-1] + item)

q = [int(item) for item in input().split()]
for np in q:
    r_index = bisect.bisect_left(places, np)
    l_index = n - r_index
    ans = r_x_cum[r_index] * np + r_1_cum[r_index]
    ans += l_x_cum[l_index] * np + l_1_cum[l_index]
    print(ans)
0