結果

問題 No.1012 荷物収集
ユーザー はむ吉🐹はむ吉🐹
提出日時 2020-03-20 22:43:43
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,126 bytes
コンパイル時間 913 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 30,216 KB
最終ジャッジ日時 2023-08-21 17:46:52
合計ジャッジ時間 14,259 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,324 KB
testcase_01 AC 17 ms
8,280 KB
testcase_02 AC 17 ms
8,288 KB
testcase_03 AC 17 ms
8,288 KB
testcase_04 AC 497 ms
30,168 KB
testcase_05 AC 493 ms
30,144 KB
testcase_06 AC 488 ms
30,216 KB
testcase_07 AC 494 ms
30,092 KB
testcase_08 AC 496 ms
30,136 KB
testcase_09 AC 497 ms
30,144 KB
testcase_10 AC 491 ms
30,144 KB
testcase_11 AC 497 ms
30,028 KB
testcase_12 AC 506 ms
30,136 KB
testcase_13 AC 497 ms
30,188 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 17 ms
8,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import bisect
import itertools


class CumulativeSum(object):

    def __init__(self, sequence):
        self.cumulative_sum = [0]
        self.cumulative_sum.extend(itertools.accumulate(sequence))

    def partial_sum(self, first, last):
        return self.cumulative_sum[last + 1] - self.cumulative_sum[first]


def process_queries(xs, ws, ys):
    n = len(xs)
    w_cs = CumulativeSum(ws)
    xw_cs = CumulativeSum(x * w for x, w in zip(xs, ws))
    for y in ys:
        pos = bisect.bisect(xs, y)
        left_sum = y * w_cs.partial_sum(0, pos - 1) - \
            xw_cs.partial_sum(0, pos - 1)
        right_sum = xw_cs.partial_sum(
            pos, n - 1) - y * w_cs.partial_sum(pos, n - 1)
        all_sum = left_sum + right_sum
        yield all_sum


def main():
    n, q = (int(z) for z in input().split())
    xs = []
    ws = []
    for _ in range(n):
        x, w = (int(z) for z in input().split())
        xs.append(x)
        ws.append(w)
    ys = [int(z) for z in input().split()]
    for res in process_queries(xs, ws, ys):
        print(res)


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