結果

問題 No.633 バスの運賃
コンテスト
ユーザー tails1434
提出日時 2020-02-05 07:32:31
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 679 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 130 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 60,672 KB
最終ジャッジ日時 2026-04-10 05:11:49
合計ジャッジ時間 1,330 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from itertools import accumulate
from collections import defaultdict

def main():
    n = int(input())
    a = [0] + [int(input()) for _ in range(n - 1)]
    sum_a = list(accumulate(a))
    d = defaultdict(int)
    ans = 0
    for i in range(n):
        b, c = map(int, input().split())
        for j, k in d.items():
            tmp = sum_a[i] - sum_a[j]
            if k == 0:
                continue
            if b > k:
                ans += tmp * k
                d[j] = 0
                b -= k
            else:
                ans += tmp * b
                d[j] -= b
                break
        d[i] += c

    print(ans)






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