Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Say we choose k gardens to be complete, is there an optimal way of choosing which gardens to plant more flowers to achieve this?
For a given k, we should greedily fill-up the k gardens with the most flowers planted already. This gives us the most remaining flowers to fill up the other gardens.
After sorting flowers, we can thus try every possible k and what is left is to find the highest minimum flowers we can obtain by planting the remaining flowers in the other gardens.
To find the highest minimum in the other gardens, we can use binary search to find the most optimal way of planting.