Skip to content

Commit 6a98d8d

Browse files
committed
기타레슨
1 parent 67bb24e commit 6a98d8d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

[Week18 - Search]/이현동/2343.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
5+
N, M = map(int, input().split())
6+
arr = list(map(int, input().split()))
7+
8+
9+
l = max(arr)
10+
r = 1000000001
11+
mid = 0
12+
13+
while l <= r:
14+
mid = (l+r)//2
15+
cnt, tot = 0, 0
16+
for i in range(N):
17+
if(arr[i] + tot > mid):
18+
tot = 0
19+
cnt+=1
20+
tot += arr[i]
21+
22+
if tot != 0:
23+
cnt+=1
24+
25+
if cnt > M:
26+
l = mid + 1
27+
else:
28+
r = mid - 1
29+
30+
print(l)

0 commit comments

Comments
 (0)