結果
| 問題 |
No.885 アマリクエリ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-08 16:28:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,017 ms / 2,000 ms |
| コード長 | 586 bytes |
| コンパイル時間 | 424 ms |
| コンパイル使用メモリ | 82,576 KB |
| 実行使用メモリ | 100,760 KB |
| 最終ジャッジ日時 | 2024-10-03 12:12:05 |
| 合計ジャッジ時間 | 7,386 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
X = list(map(int,input().split()))
S = sum(A)
h = [-a for a in A]
heapify(h)
for i in range(Q):
x = X[i]
while True:
y = heappop(h)
y *= -1
if y<x:
heappush(h,-y)
break
S += (y%x - y)
heappush(h,-(y%x))
print(S)