結果

問題 No.885 アマリクエリ
ユーザー H3PO4
提出日時 2021-03-07 10:07:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 973 ms / 2,000 ms
コード長 369 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 81,892 KB
実行使用メモリ 102,656 KB
最終ジャッジ日時 2024-10-08 23:07:03
合計ジャッジ時間 6,433 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import heapq

input = sys.stdin.buffer.readline

N = int(input())
A = tuple(map(int, input().split()))
Q = int(input())
X = map(int, input().split())
h = [-a for a in A]
heapq.heapify(h)
cur = sum(A)
for x in X:
    while -h[0] >= x:
        a = -heapq.heappop(h)
        cur -= a
        a %= x
        cur += a
        heapq.heappush(h, -a)
    print(cur)
0