結果
| 問題 | No.885 アマリクエリ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-11-01 01:56:36 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 666 ms / 2,000 ms |
| コード長 | 449 bytes |
| 記録 | |
| コンパイル時間 | 235 ms |
| コンパイル使用メモリ | 84,992 KB |
| 実行使用メモリ | 114,648 KB |
| 最終ジャッジ日時 | 2026-03-30 07:27:00 |
| 合計ジャッジ時間 | 6,954 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
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)