Checklist : Verify convexity. Test small cases manually. If () isn't convex, the trick fails. Checklist : Handle lambda precision. Use integer arithmetic if possible. Binary search on integers is cleaner. Checklist : Track count correctly. Pair (cost, count) comparisons must be consistent. Checklist : Final answer. After finding optimal lambda, compute actual answer: . Test on small inputs where you can verify the answer manually. Check that the count varies correctly with penalty.
Time complexity: .
Space complexity: in time and in space.