
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
If you can place balls such that the answer is x then you can do it for y where y < x.
Similarly if you cannot place balls such that the answer is x then you can do it for y where y > x.
Binary search on the answer and greedily see if it is possible.