-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
17-janghw0126 #186
base: main
Are you sure you want to change the base?
17-janghw0126 #186
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ°λ‘ μ΄λΆνμ λ¬Έμ λΌκ³ νμ
νμ κ² λλ¨ν κ±° κ°μμ...!!
μ λ μ΄λ²μ νμ΄μ¬μΌλ‘ νμ΄λ΄€λλ° μ 체μ μΈ νμ΄λ λΉμ·νμ§λ§
count = 0
for line in lines :
count += line // mid
μ΄ λΆλΆμ
count = sum(cable // mid for cable in cables)
νμ λμ²λΌ μ΄λ κ² μ€μ¬μ°λ 건 λ§μ μ°μ΅μ΄ νμν κ² κ°μ΅λλ€ π₯Ή μ΄λ κ² μ½λ λΌμΈ μ μ€μΌ μ μλ κ² νμ΄μ¬μ μ₯μ μ΄λΌκ³ μκ°νλλ° μ΅μνμ§ μλ€μ,,,
μλλ νμ΄ μ½λμ λλ€! μ΄λ² μ°¨μλ μκ³ νμ ¨μ΄μ!
# λ°±μ€ - λμ μλ₯΄κΈ°(1654)
import sys
K, N = map(int, sys.stdin.readline().split())
lines = []
for i in range(K) :
lines.append(int(sys.stdin.readline()))
left = 1
right = max(lines)
while left <= right :
mid = (left + right) // 2
count = 0
for line in lines :
count += line // mid
if(count >= N) :
left = mid + 1
else :
right = mid - 1
print(right)
π λ¬Έμ λ§ν¬
λ°±μ€ | λμ μλ₯΄κΈ°
βοΈ μμλ μκ°
30λΆ
β¨ μλ μ½λ
μ΄ λ¬Έμ λ νμ¬ κ°μ§κ³ μλ λμ μ μλ€κ³Ό κΈΈμ΄λ₯Ό μλ €μ£Όκ³ , μ΅λ λͺ μΌμΉμ κΈΈμ΄λ₯Ό μλΌμΌ μ΅λλ‘ μμ μ΄ μνλ κ°―μλ₯Ό μ»μ μ μλμ§ κ΅¬νλ λ¬Έμ μμ΅λλ€.
μ§λ¬Έμ 보μλ§μ λμ μ μλ₯΄λ λ¬Έμ μ΄λ―λ‘ μ΄λΆ νμμ μ΄μ©νλ©΄ μ½κ² ν μ μμ κ²μ΄λΌκ³ μκ°νμμ΅λλ€.
π₯ λ¬Έμ ν΄κ²° λ‘μ§
( low + high ) // 2
λ‘ μ‘°μ ν΄μ€λλ€.count
λ³μμ μ μ₯ν©λλ€.mid + 1
λ‘ μ‘°μ ν΄ μ€λλ€.mid - 1
λ‘ μ‘°μ ν΄ μ€λλ€.high
μ κ°μ₯ κΈ΄ λμ μ κΈΈμ΄κ° μ μ₯λ©λλ€.μ΄λ₯Ό λ°νμΌλ‘ μ½λλ₯Ό μμ±νμμ΅λλ€.
π©βπ»μ΅μ’ μ½λ
μν λλκ³ μλ°μ μΌλ‘ λ¬λ¦¬κ³ μλλ° μ΄λΆ νμλ μ μκ² κ°μκΈ° μλ‘μ΄ λ¬Έμ μ²λΌ λκ»΄μ§λ€μ...!
μμ§ κ° κΈΈμ΄ λ¨Ό κ°μλ°λΆμΈκ±Έ λͺΈμ λλλλ€...π₯π
π μλ‘κ² μκ²λ λ΄μ©
.