結果
| 問題 | No.885 アマリクエリ |
| コンテスト | |
| ユーザー |
dn6049949
|
| 提出日時 | 2019-09-14 00:05:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 982 ms / 2,000 ms |
| コード長 | 3,129 bytes |
| コンパイル時間 | 169 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 98,816 KB |
| 最終ジャッジ日時 | 2024-07-04 10:40:45 |
| 合計ジャッジ時間 | 6,540 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
a,b = LI()
for i in range(1,101):
if a%i == 0 and i%b == 0:
print("YES")
return
print("NO")
return
#B
def B():
n,k = LI()
if n >= k**2:
h = math.ceil(n/k)
s = []
l = 0
for i in range(n//k):
s.append(["#" if l <= i < l+k or (i < (l+k)%h and l+k >= h) else "." for i in range(h)])
l += 1
l %= h
su = n%k
if su:
s.append(["#" if l <= i < l+su else "." for i in range(h)])
print(h)
for i in s:
print(*i,sep="")
else:
p = n//(k**2)
n_ = n-p*k**2
for k_ in range(100000):
if k_**2 >= n_:break
h = p*k+k_
s = []
l = 0
r = k
for i in range(p):
for j in range(k):
s.append(["#" if l <= i < r else "." for i in range(h)])
l,r = r,r+k
for j in range(k_):
s.append(["#" if l <= i < r else "." for i in range(h)])
su = p*k**2+k_**2
for i in range(p*k,h)[::-1]:
if su == n:
break
s[-1][i] = "."
su -= 1
for i in range(p*k,h-1)[::-1]:
if su == n:
break
s[i][-1] = "."
su -= 1
print(h)
for i in s:
print(*i,sep = "")
return
#C
def C():
s = list(map(int, input()))
s = s[::-1]
s.append(0)
n = len(s)
dp = [[float("inf")]*2 for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
if s[i] == 0:
dp[i+1][0] = min(dp[i+1][0],dp[i][0])
dp[i+1][0] = min(dp[i+1][0],dp[i][1]+1)
dp[i+1][1] = min(dp[i+1][1],dp[i][1]+1)
else:
dp[i+1][0] = min(dp[i+1][0],dp[i][0]+1)
dp[i+1][1] = min(dp[i+1][1],dp[i][0]+1)
dp[i+1][1] = min(dp[i+1][1],dp[i][1])
print(min(dp[n]))
return
#D
def D():
n = I()
a = LI()
q = []
for i in a:
heappush(q,-i)
Q = I()
x = LI()
ans = sum(a)
for i in range(Q):
xi = x[i]
while 1:
y = heappop(q)
y *= -1
if y < xi:
heappush(q,-y)
break
ans -= y-y%xi
y %= xi
heappush(q,-y)
print(ans)
return
#E
def E():
return
#F
def F():
return
#Solve
if __name__ == "__main__":
D()
dn6049949