結果
| 問題 | No.885 アマリクエリ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-09 22:22:19 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 441 ms / 2,000 ms |
| コード長 | 547 bytes |
| 記録 | |
| コンパイル時間 | 700 ms |
| コンパイル使用メモリ | 85,492 KB |
| 実行使用メモリ | 160,336 KB |
| 最終ジャッジ日時 | 2026-03-31 16:59:17 |
| 合計ジャッジ時間 | 3,538 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
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)