3
self, flowers: List[int], newFlowers: int, target: int, full: int, partial: int6
# move out already completed garden20
presum = [0] + list(accumulate(flowers))25
for i in range(N + 1):26
# iterate all index: left part is all partial, right part (>= i) is all complete28
# update the dp arr for binary search below30
dp_arr.append((i + 1) * flowers[i] - presum[i + 1])32
right_sum = presum[-1] - presum[i]35
# if can't make the right part all complete, go to next index36
if right_sum + newFlowers < right_count * target:39
# remaining flowers after making right part all complete40
rem_flowers = newFlowers - (right_count * target - right_sum)42
# binary search to find the maximum possible min flowers in the left part (named 'min_partial')46
j = min(bisect.bisect_right(dp_arr, rem_flowers) - 1, i - 1)47
min_partial = min((rem_flowers + presum[j + 1]) // (j + 1), target - 1)49
complete = right_count + already_complete50
max_beauty = max(max_beauty, complete * full + min_partial * partial)