結果

問題 No.885 アマリクエリ
ユーザー stng
提出日時 2022-08-08 13:53:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 785 ms / 2,000 ms
コード長 658 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 94,392 KB
最終ジャッジ日時 2024-09-19 00:20:57
合計ジャッジ時間 5,600 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
x = [int(i) for i in input().split()]

qry = x[0]
li = []
heapq.heapify(li)
now = 0
for i in range(n):
    tmp = a[i] % qry
    if tmp != 0:
        now += tmp
        heapq.heappush(li,-tmp)

print(now)

for i in range(q-1):
    qry = x[i+1]
    f = True
    while len(li) and f == True:
        tmp = heapq.heappop(li)
        if -tmp >= qry:
            now -= -tmp
            tmp = (-tmp) % qry
            now += tmp
            if tmp != 0:
                heapq.heappush(li,-tmp)
        else:
            f = False
            heapq.heappush(li,tmp)
    print(now)
0