Maximum Total Beauty of the Gardens
international master · 1970 · lc hard +32 · verified · 30.4% accepted · 451 likes · top 8%
Description
Alice tends n gardens and wants to maximize their combined beauty through additional planting.
You are given a 0-indexed integer array flowers of size n where flowers[i] is the existing flower count in garden i (already-planted flowers cannot be removed). You are also given newFlowers (the maximum additional flowers Alice may plant), along with integers target, full, and partial.
A garden is complete when it has at least target flowers. Total beauty is:
- The number of complete gardens times full, plus
- The minimum flower count across all incomplete gardens times partial (this term is 0 when no incomplete gardens remain).
Return the maximum total beauty achievable by planting at most newFlowers additional flowers.
Example 1:
Example 2:
Code