ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 2805 |
문제명 | 나무 자르기 |
레벨 | 실버 3 |
분류 |
파라메트릭 서치 |
시간복잡도 | O(nlogn) |
인풋사이즈 | n <= 1,000,000 |
사용한 언어 | Python |
제출기록 | 146524KB / 860ms |
최고기록 | 440ms |
해결날짜 | 2021/07/18 |
태그 |
"""Solution code for "BOJ 2805. 나무 자르기".
- Problem link: https://www.acmicpc.net/problem/2805
- Solution link: http://www.teferi.net/ps/problems/boj/2805
"""
from teflib import algorithm
def main():
def is_less_than_m(height):
total = 0
for t in trees:
if t <= height:
return True
total += t - height
if total >= M:
return False
return True
N, M = [int(x) for x in input().split()]
trees = [int(x) for x in input().split()]
trees.sort(reverse=True)
answer = algorithm.binary_search(0, max(trees) + 2, is_less_than_m) - 1
print(answer)
if __name__ == '__main__':
main()
"""Solution code for "BOJ 2805. 나무 자르기".
- Problem link: https://www.acmicpc.net/problem/2805
- Solution link: http://www.teferi.net/ps/problems/boj/2805
"""
def main():
N, M = [int(x) for x in input().split()]
trees = [int(x) for x in input().split()]
trees.sort(reverse=True)
trees.append(0)
total_cut = 0
for i in range(1, N + 1):
total_cut += (trees[i - 1] - trees[i]) * i
if total_cut >= M:
answer = trees[i] + (total_cut - M) // i
break
print(answer)
if __name__ == '__main__':
main()