結果

問題 No.885 アマリクエリ
ユーザー maspymaspy
提出日時 2020-02-06 10:37:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 950 ms / 2,000 ms
コード長 506 bytes
コンパイル時間 1,095 ms
コンパイル使用メモリ 81,488 KB
実行使用メモリ 107,992 KB
最終ジャッジ日時 2023-10-25 09:53:53
合計ジャッジ時間 6,846 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 950 ms
107,200 KB
testcase_01 AC 407 ms
101,380 KB
testcase_02 AC 177 ms
101,392 KB
testcase_03 AC 159 ms
101,488 KB
testcase_04 AC 161 ms
101,488 KB
testcase_05 AC 112 ms
107,992 KB
testcase_06 AC 106 ms
105,540 KB
testcase_07 AC 94 ms
91,604 KB
testcase_08 AC 74 ms
94,800 KB
testcase_09 AC 402 ms
101,380 KB
testcase_10 AC 39 ms
53,420 KB
testcase_11 AC 39 ms
53,420 KB
testcase_12 AC 39 ms
53,420 KB
testcase_13 AC 72 ms
73,796 KB
testcase_14 AC 71 ms
73,912 KB
testcase_15 AC 71 ms
73,672 KB
testcase_16 AC 54 ms
63,944 KB
testcase_17 AC 44 ms
59,228 KB
testcase_18 AC 53 ms
65,992 KB
testcase_19 AC 43 ms
59,076 KB
testcase_20 AC 38 ms
53,420 KB
testcase_21 AC 54 ms
65,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappop, heappush, heapify

N = int(readline())
*A, = map(int,readline().split())
Q = int(readline())
*X, = map(int,readline().split())

q = [-x for x in A]
heapify(q)
S = sum(A)
answers = []
for x in X:
    while -q[0] >= x:
        a = -heappop(q)
        r = a % x
        S -= (a - r)
        heappush(q, -r)
    answers.append(S)

print('\n'.join(map(str, answers)))
0