結果
問題 |
No.885 アマリクエリ
|
ユーザー |
|
提出日時 | 2022-05-09 22:22:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 671 ms / 2,000 ms |
コード長 | 547 bytes |
コンパイル時間 | 213 ms |
コンパイル使用メモリ | 82,448 KB |
実行使用メモリ | 166,324 KB |
最終ジャッジ日時 | 2024-07-17 03:23:50 |
合計ジャッジ時間 | 5,215 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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)