• Home
  • About
    • JOOS photo

      JOOS

      Joos's blog

    • Learn More
    • Email
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

[백준] 2805번 : 나무자르기 with python3

14 Aug 2018

Reading time ~1 minute

문제 : https://www.acmicpc.net/problem/2805

N, M = map(int, input().split())
heights = list(map(int, input().split()))

l = 1
r = max(heights)

ans = 0
while l <= r:
    mid = (l+r)//2
    remain = sum(t-mid for t in heights if t-mid > 0)
    if remain < M:
        r = mid-1
    else:
        if ans < mid:
            ans = mid
        l = mid+1
print(ans)



algorithm백준 Share Tweet +1