Skip to content

Commit d6f4f91

Browse files
committed
[23.01.30/Python] 예산
1 parent a95851a commit d6f4f91

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
.idea/workspace.xml
44
.idea/misc.xml
55
.idea/codingtest.iml
6+
*.class
7+
*.xml
8+
BOJ_JAVA/.idea/misc.xml
9+
BOJ_JAVA/.DS_Store
10+
.DS_Store
11+
theory_Python/.DS_Store

Python_BOJ_2023/2512.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 예산
2+
n = int(input())
3+
arra = list(map(int, input().split()))
4+
m = int(input())
5+
arra.sort()
6+
7+
def binary_search(arr):
8+
start = 0
9+
end = max(arr)
10+
11+
while start <= end:
12+
mid = (start + end) // 2
13+
print(start, end, mid)
14+
cnt = 0
15+
for i in range(n):
16+
if arr[i] >= mid:
17+
cnt += mid
18+
else:
19+
cnt += arr[i]
20+
if cnt <= m:
21+
start = mid + 1
22+
else:
23+
end = mid - 1
24+
return end
25+
26+
answer = binary_search(arra)
27+
print(answer)

0 commit comments

Comments
 (0)