diff --git "a/xxubin04/Binary Search/2805_\353\202\230\353\254\264 \354\236\220\353\245\264\352\270\260.py" "b/xxubin04/Binary Search/2805_\353\202\230\353\254\264 \354\236\220\353\245\264\352\270\260.py" new file mode 100644 index 0000000..be47f69 --- /dev/null +++ "b/xxubin04/Binary Search/2805_\353\202\230\353\254\264 \354\236\220\353\245\264\352\270\260.py" @@ -0,0 +1,33 @@ +input = open(0).readline + +tree_num, length = map(int, input().split()) +trees = sorted(list(map(int, input().split()))) + +def binary_search(target, trees): + start = 0 + end = trees[-1] + + while start <= end: + mid = (start + end) // 2 + cutted_trees = 0 + + for i in trees: + if (i - mid) >= 0: + cutted_trees += (i - mid) + + if cutted_trees == target: + return mid + elif cutted_trees > target: + start = mid + 1 + else: + end = mid - 1 + + if cutted_trees >= target: + ans = mid + else: + ans = mid - 1 + + return ans + + +print(binary_search(length, trees)) \ No newline at end of file diff --git a/xxubin04/README.md b/xxubin04/README.md index 67dbd0f..e2faadf 100644 --- a/xxubin04/README.md +++ b/xxubin04/README.md @@ -28,4 +28,5 @@ | 24차시 | 2024.01.29 | DP | [1495]기타리스트 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/86 | | 25차시 | 2024.02.01 | 구현 | [13]Roman to Integer | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/91 | | 26차시 | 2024.02.05 | 에라토스테네스의 체 | [4948]베르트랑 공준 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/94 | -| 27차시 | 2024.02.08 | 수학 | [2885]초콜릿 식사 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/98 | \ No newline at end of file +| 27차시 | 2024.02.08 | 수학 | [2885]초콜릿 식사 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/98 | +| 28차시 | 2024.02.15 | 이진탐색 | [2805]나무 자르기 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/108 | \ No newline at end of file