結果

問題 No.885 アマリクエリ
ユーザー tamatotamato
提出日時 2020-02-19 15:37:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 771 ms / 2,000 ms
コード長 720 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 175,904 KB
最終ジャッジ日時 2024-04-16 21:39:17
合計ジャッジ時間 6,202 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 771 ms
175,904 KB
testcase_01 AC 488 ms
110,796 KB
testcase_02 AC 265 ms
94,464 KB
testcase_03 AC 193 ms
93,696 KB
testcase_04 AC 195 ms
94,100 KB
testcase_05 AC 156 ms
99,456 KB
testcase_06 AC 150 ms
100,608 KB
testcase_07 AC 109 ms
89,344 KB
testcase_08 AC 122 ms
90,368 KB
testcase_09 AC 491 ms
105,692 KB
testcase_10 AC 44 ms
52,480 KB
testcase_11 AC 44 ms
52,096 KB
testcase_12 AC 44 ms
52,224 KB
testcase_13 AC 109 ms
76,444 KB
testcase_14 AC 110 ms
76,800 KB
testcase_15 AC 111 ms
76,160 KB
testcase_16 AC 74 ms
67,328 KB
testcase_17 AC 65 ms
64,384 KB
testcase_18 AC 83 ms
70,784 KB
testcase_19 AC 51 ms
59,008 KB
testcase_20 AC 61 ms
62,464 KB
testcase_21 AC 66 ms
64,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    from heapq import heappush, heappop, heapify
    input = sys.stdin.readline

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

    for i in range(N):
        A[i] *= -1

    heapify(A)
    ans = -sum(A)
    for x in X:
        tmp = []
        #print(x, A)
        while A:
            a = -heappop(A)
            #print(x, a)
            if a >= x:
                ans -= a - a%x
                a = a%x
                tmp.append(a)
            else:
                heappush(A, -a)
                break
        for a in tmp:
            heappush(A, -a)
        print(ans)


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