Problem 3684 · Medium

Maximize Sum of At Most K Distinct Elements

Sort the distinct values from largest to smallest and keep the first k; every value is positive, so more picks always help.

Open the interactive visualisation