Skip to content

Commit 3e11a88

Browse files
committed
86차 2번 문제 풀이
1 parent 80f599f commit 3e11a88

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

live8/test86/문제2/박희경.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
3+
4+
def binary_search(arr, target):
5+
start, end = 0, max(arr)
6+
while start <= end:
7+
mid = (start + end) // 2
8+
total = 0
9+
for i in arr:
10+
if i > mid:
11+
total += mid
12+
else:
13+
total += i
14+
if total > target:
15+
end = mid - 1
16+
else:
17+
start = mid + 1
18+
return end
19+
20+
21+
input = sys.stdin.readline
22+
23+
n = int(input())
24+
budget = list(map(int, input().split()))
25+
m = int(input())
26+
27+
budget.sort() # 110 120 140 150
28+
print(binary_search(budget, m))
29+
30+
31+
"""
32+
4
33+
120 110 140 150
34+
485
35+
36+
5
37+
70 80 30 40 100
38+
450
39+
"""

0 commit comments

Comments
 (0)