結果

問題 No.885 アマリクエリ
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-05-09 22:22:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 576 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 162,560 KB
最終ジャッジ日時 2023-09-24 03:16:18
合計ジャッジ時間 6,949 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
94,132 KB
testcase_01 AC 511 ms
145,280 KB
testcase_02 AC 199 ms
116,072 KB
testcase_03 AC 115 ms
93,712 KB
testcase_04 AC 114 ms
93,908 KB
testcase_05 AC 115 ms
95,044 KB
testcase_06 AC 108 ms
98,516 KB
testcase_07 AC 103 ms
98,168 KB
testcase_08 AC 99 ms
91,744 KB
testcase_09 AC 576 ms
162,560 KB
testcase_10 AC 73 ms
71,316 KB
testcase_11 AC 66 ms
70,940 KB
testcase_12 AC 68 ms
71,408 KB
testcase_13 AC 103 ms
77,992 KB
testcase_14 AC 101 ms
77,892 KB
testcase_15 AC 102 ms
78,028 KB
testcase_16 AC 73 ms
76,140 KB
testcase_17 AC 74 ms
76,312 KB
testcase_18 AC 83 ms
76,388 KB
testcase_19 AC 66 ms
71,264 KB
testcase_20 AC 70 ms
75,256 KB
testcase_21 AC 76 ms
75,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush

n = int(input())
A = list(map(int,input().split()))
q = int(input())
X = list(map(int,input().split()))

ans = sum(A)
dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1

h = []
for key in dic.keys():
    heappush(h,-key)

for x in X:
    while -h[0] >= x:
        key = -heappop(h)
        num = dic[key]
        ans -= key*num
        nkey = key%x
        ans += nkey*num
        if nkey in dic:
            dic[nkey] += num
        else:
            dic[nkey] = num
            heappush(h,-nkey)
    print(ans)
0