Maximum Total Beauty of the Gardens - Problem
πΊ Maximum Total Beauty of the Gardens
Alice manages n gardens and wants to strategically plant flowers to achieve the maximum total beauty possible!
You're given:
flowers[]- Current flower count in each gardennewFlowers- Additional flowers Alice can planttarget- Minimum flowers needed for a garden to be "complete"full- Beauty points per complete gardenpartial- Multiplier for the minimum flowers among incomplete gardens
Beauty Calculation:
- Complete gardens: Each garden with β₯
targetflowers contributesfullpoints - Incomplete gardens: The garden with the fewest flowers among all incomplete gardens contributes
min_flowers Γ partialpoints
Your goal is to determine how to distribute the newFlowers to maximize total beauty!
Input & Output
example_1.py β Basic Case
$
Input:
flowers = [1,3,1,1], newFlowers = 7, target = 6, full = 12, partial = 1
βΊ
Output:
14
π‘ Note:
We can make 1 garden complete by spending 6-3=3 flowers on garden[1]. The remaining 4 flowers can raise gardens [1,1,1] to [2,2,2] (minimum=2). Total beauty = 1Γ12 + 2Γ1 = 14.
example_2.py β All Complete Strategy
$
Input:
flowers = [2,4,5,3], newFlowers = 10, target = 5, full = 2, partial = 6
βΊ
Output:
30
π‘ Note:
Better to make all gardens complete: costs 3+1+0+2=6 flowers. Total beauty = 4Γ2 + 0Γ6 = 8. Wait, that's wrong - let me recalculate... Actually optimal is 15Γ2 = 30 when we achieve minimum 5 for incomplete.
example_3.py β Edge Case - All Already Complete
$
Input:
flowers = [5,5,5], newFlowers = 5, target = 5, full = 3, partial = 2
βΊ
Output:
9
π‘ Note:
All gardens are already complete (β₯5 flowers). No incomplete gardens exist, so partial contribution is 0. Total beauty = 3Γ3 + 0Γ2 = 9.
Constraints
- 1 β€ flowers.length β€ 105
- 1 β€ flowers[i], target β€ 105
- 1 β€ newFlowers β€ 1010
- 1 β€ full, partial β€ 105
- Key insight: newFlowers can be very large, but we never need more than nΓtarget flowers
π‘
Explanation
AI Ready
π‘ Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code