結果

問題 No.885 アマリクエリ
ユーザー kohei2019
提出日時 2022-05-11 23:08:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 850 ms / 2,000 ms
コード長 445 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 102,328 KB
最終ジャッジ日時 2024-07-19 09:00:18
合計ジャッジ時間 6,142 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
N = int(input())
h = list(map(int, input().split()))
Q = int(input())
lsX = list(map(int, input().split()))

h = [-i for i in h]
heapq.heapify(h)

allsum = -sum(h) 
for i in range(Q):
    x = lsX[i]
    while True:
        p = heapq.heappop(h)
        if p <= -x:
            n = (-p)%x
            allsum -= (-p)-n
            heapq.heappush(h, -n)
        else:
            heapq.heappush(h, p)
            break
    print(allsum)
0