結果

問題 No.885 アマリクエリ
コンテスト
ユーザー LyricalMaestro
提出日時 2025-11-12 21:32:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 945 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 82,912 KB
実行使用メモリ 107,448 KB
最終ジャッジ日時 2025-11-12 21:32:43
合計ジャッジ時間 7,184 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/1552

import heapq

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

    answer = sum(A)
    queue = []
    for a in A:
        heapq.heappush(queue, -a)
    
    for x in X:
        while len(queue) > 0 and queue[0] <= -x:
            a = heapq.heappop(queue)
            a = -a
            answer -=a
            b = a % x
            heapq.heappush(queue, -b)
            answer += b
        print(answer)









if __name__ == "__main__":
    main()
0