All problems

Quiz Night Podium

Easy · heap

The village hall has run a quiz night. scores[i] is the final score of team i, and the teams are numbered from 0.

The k highest-scoring teams are invited onto the stage. Return the numbers of those k teams, with the best team first. If two teams have the same score, the team with the smaller number comes first.

Examples

Example 1

Input: scores = [40, 75, 75, 10, 60], k = 3

Output: [1, 2, 4]

The best score is 75, shared by teams 1 and 2, and the smaller number goes first. The next best is team 4 with 60.

Example 2

Input: scores = [5, 5, 5], k = 2

Output: [0, 1]

Every team ties, so the two smallest team numbers are invited.

Example 3

Input: scores = [90], k = 1

Output: [0]

Constraints