λ¬Έμ
https://www.acmicpc.net/problem/2512
νμ΄
# λ°±μ€ 2512λ² λ¬Έμ - μμ°
n = int(input())
money = list(map(int, input().split()))
budget = int(input())
start, end = 0, max(money)
def binary(money):
start = 0
end = max(money)
while start <= end:
mid = (start + end) // 2
cnt = 0
for i in money:
if i >= mid:
cnt += mid
else:
cnt += i
if cnt <= budget:
start = mid + 1
else:
end = mid - 1
return end
print(binary(money))
κΈ°λ³Έμ μΈ μ΄μ§νμ λ¬Έμ μ΄λ€.
μ΄μ§νμμ΄μ΄μ μ λ ¬μ ν΄μΌλλ€κ³ μκ°νλλ° μ΄μ°¨νΌ λͺ¨λ λμ νμΈνκ³ λν΄μ€μ μ λ ¬ν νμκ° μμλ€.
'ποΈ Algorithm > π© λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
π© [λ°±μ€] [Python] [Gold1] 2042λ²_κ΅¬κ° ν© κ΅¬νκΈ° (0) | 2023.04.24 |
---|---|
π© [λ°±μ€] [Python] [Silver3] 11478λ²_μλ‘ λ€λ₯Έ λΆλΆ λ¬Έμμ΄μ κ°μ (0) | 2023.04.23 |
π© [λ°±μ€] [Python] [Gold5] 1107λ²_리λͺ¨μ»¨ (1) | 2023.04.21 |
π© [λ°±μ€] [Python] [Gold5] 9251λ²_LCS (0) | 2023.04.21 |
π© [λ°±μ€] [Python] [Gold5] 1011λ²_Fly me to the Alpha Centauri (0) | 2023.04.21 |