I think this is an easy problem, not medium. Althogh, it was take some time for me to understand it describe.
https://leetcode.com/problems/maximize-happiness-of-selected-children/
var maximumHappinessSum = function (happiness, k) {
let sorted = happiness.toSorted((a, b) => a - b);
let d = 0;
let s = 0;
for (let i = 0; i < k; i++) {
let v = sorted.pop();
if (v - i <= 0) break;
s += v - i;
}
return s;
};