結果

問題 No.885 アマリクエリ
ユーザー ntuda
提出日時 2025-05-03 12:13:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 809 ms / 2,000 ms
コード長 307 bytes
コンパイル時間 496 ms
コンパイル使用メモリ 82,648 KB
実行使用メモリ 94,852 KB
最終ジャッジ日時 2025-05-03 12:13:18
合計ジャッジ時間 6,008 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

N = int(input())
A = list(map(int,input().split()))
ans = sum(A)
Q = [-a for a in A]
heapify(Q)
_ = int(input())
X = list(map(int,input().split()))

for x in X:
    while -Q[0] >= x:
        y = -heappop(Q)
        yx = y % x
        ans -= y - yx
        heappush(Q,-yx)
    print(ans)
0