forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path8.py
More file actions
28 lines (25 loc) Β· 864 Bytes
/
8.py
File metadata and controls
28 lines (25 loc) Β· 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# λ‘μ κ°μ(N)μ μμ²ν λ‘μ κΈΈμ΄(M)μ μ
λ ₯
n, m = list(map(int, input().split(' ')))
# κ° λ‘μ κ°λ³ λμ΄ μ 보λ₯Ό μ
λ ₯
array = list(map(int, input().split()))
# μ΄μ§ νμμ μν μμμ κ³Ό λμ μ€μ
start = 0
end = max(array)
# μ΄μ§ νμ μν (λ°λ³΅μ )
result = 0
while(start <= end):
total = 0
mid = (start + end) // 2
for x in array:
# μλμ λμ λ‘λ³Άμ΄ μ κ³μ°
if x > mid:
total += x - mid
# λ‘λ³Άμ΄ μμ΄ λΆμ‘±ν κ²½μ° λ λ§μ΄ μλ₯΄κΈ° (μ€λ₯Έμͺ½ λΆλΆ νμ)
if total < m:
end = mid - 1
# λ‘λ³Άμ΄ μμ΄ μΆ©λΆν κ²½μ° λ μλ₯΄κΈ° (μΌμͺ½ λΆλΆ νμ)
else:
result = mid # μ΅λν λ μλμ λκ° μ λ΅μ΄λ―λ‘, μ¬κΈ°μμ resultμ κΈ°λ‘
start = mid + 1
# μ λ΅ μΆλ ₯
print(result)