結果

問題 No.885 アマリクエリ
ユーザー qib
提出日時 2022-11-01 01:56:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 864 ms / 2,000 ms
コード長 449 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 107,008 KB
最終ジャッジ日時 2024-07-08 13:21:22
合計ジャッジ時間 6,297 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

n = int(input())
a = list(map(int, input().split()))
q = int(input())
x = list(map(int, input().split()))

ans = 0
hp = []
for i in range(n):
  ans += a[i]
  heapq.heappush(hp, - a[i])

for i in range(q):
  while True:
    cur = heapq.heappop(hp)
    if - cur < x[i]:
      heapq.heappush(hp, cur)
      break
    else:
      ans -= (- cur)
      nxt = - ((- cur) % x[i])
      ans += (- nxt)
      heapq.heappush(hp, nxt)
  print(ans)
0