結果

問題 No.885 アマリクエリ
ユーザー ああいいああいい
提出日時 2022-01-09 18:06:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 973 ms / 2,000 ms
コード長 419 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 82,216 KB
実行使用メモリ 102,924 KB
最終ジャッジ日時 2024-11-14 10:27:17
合計ジャッジ時間 6,572 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
X = list(map(int,input().split()))

Sum = sum(A)

A = [-a for a in A]
import heapq
heapq.heapify(A)

for x in X:
    while True:
        u = heapq.heappop(A)
        u = -u
        if u < x:
            heapq.heappush(A,-u)
            break
        else:
            t = u % x
            Sum -= (u-t)
            heapq.heappush(A,-t)
    print(Sum)
0