complete 1654.py
This commit is contained in:
24
zeta_python/1214.py
Normal file
24
zeta_python/1214.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Px+Qy >= D
|
||||||
|
def solve(D, P, Q):
|
||||||
|
if D % P == 0 or D % Q == 0:
|
||||||
|
return D
|
||||||
|
Q, P = sorted((P, Q))
|
||||||
|
p_bound = (D // P) + 1
|
||||||
|
|
||||||
|
min_S = 10 ** 13
|
||||||
|
for x in range(0, p_bound + 1):
|
||||||
|
|
||||||
|
d, m = divmod(D - P * x, Q)
|
||||||
|
if m == 0:
|
||||||
|
return D
|
||||||
|
new_S = (d + 1) * Q + P * x
|
||||||
|
if new_S < min_S:
|
||||||
|
min_S = new_S
|
||||||
|
if min_S == D:
|
||||||
|
return min_S
|
||||||
|
return min_S
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
D, P, Q = map(int, input().split())
|
||||||
|
print(solve(D, P, Q))
|
||||||
25
zeta_python/completed/1654.py
Normal file
25
zeta_python/completed/1654.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
|
||||||
|
def solve(K, N, E):
|
||||||
|
before = 1
|
||||||
|
head = max(E)
|
||||||
|
mid = (head + before) // 2
|
||||||
|
# do
|
||||||
|
S = sum(e // mid for e in E)
|
||||||
|
while before <= head:
|
||||||
|
if S >= N:
|
||||||
|
before = mid + 1
|
||||||
|
else:
|
||||||
|
head = mid - 1
|
||||||
|
mid = (before + head) // 2
|
||||||
|
S = sum(e // mid for e in E)
|
||||||
|
return mid
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
K, N = map(int, input().split())
|
||||||
|
E = [int(input()) for _ in range(K)]
|
||||||
|
print(solve(K, N, E))
|
||||||
Reference in New Issue
Block a user