# BOJ - 6236 - 용돈 관리

Updated:

```
import sys
def solution():
N, M = map(int, sys.stdin.readline().split())
money = []
for _ in range(N):
money.append(int(sys.stdin.readline()))
left, right = 0, sum(money)
result = sum(money)
while left <= right:
mid = (left + right) // 2
temp = mid
flag = False
cnt = 1
for i in range(N):
if mid < money[i]:
flag = True
break
if temp < money[i]:
temp = mid
cnt += 1
temp -= money[i]
if flag == False:
if cnt <= M:
right = mid - 1
if mid < result:
result = mid
else:
left = mid + 1
else:
left = mid + 1
print(result)
solution()
```

https://www.acmicpc.net/problem/6236

## Leave a comment