n employees. Employee i has a rank ranks[i] and a bonus bonuses[i].
For each employee i, look at everyone whose rank is **strictly lower** than ranks[i] and pick at most k of their bonuses so that the total is as large as possible. If nobody has a lower rank, the total is 0.
Return a list of length n whose i-th element is that maximum total for employee i.ranks=[3, 1, 4, 2], bonuses=[7, 9, 5, 6], k=2 → [15, 0, 16, 9]
Employee 0 (rank 3) outranks employees 1 and 3 with bonuses 9 and 6, giving 15. Employee 1 outranks nobody, so 0. Employee 2 (rank 4) outranks everyone else; the two best bonuses are 9 and 7, giving 16. Employee 3 (rank 2) outranks only employee 1, giving 9.
ranks=[5, 5, 2], bonuses=[4, 8, 3], k=3 → [3, 3, 0]
An equal rank does not count as lower: employees 0 and 1 can only take employee 2's bonus, which is 3.
ranks=[1, 2, 3, 4], bonuses=[10, 1, 1, 1], k=1 → [0, 10, 10, 10]
len(ranks) == len(bonuses) == nranks[i], bonuses[i] ≤ 10⁶ranks=[3, 1, 4, 2], bonuses=[7, 9, 5, 6], k=2
[15, 0, 16, 9]
Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.