2305. Fair Distribution of Cookies
Содержание
class Solution:
def distributeCookies(self, cookies: List[int], k: int) -> int:
def dfs(i):
if i >= len(cookies):
nonlocal res
res = max(cnt)
return
for j in range(k):
if cnt[j] + cookies[i] >= res or (j and cnt[j] == cnt[j - 1]):
continue
cnt[j] += cookies[i]
dfs(i + 1)
cnt[j] -= cookies[i]
res = inf
cnt = [0] * k
cookies.sort(reverse=True)
dfs(0)
return res