MicrosoftOA #57
Rank Open Businesses
Estimated EasyJudge-ready
Topics (AI-labelled)In-place Arrays
Consider only open merchants and rank them by rating in descending order, then by distance in ascending order, then by original input index in ascending order. Return the first K indices; if fewer merchants are open, return all of them.
This site uses a standard input/output protocol.
Input
The first line contains N K, followed by N lines score distance isOpen. This site uses 1≤N≤100000, 0≤K≤100000, ratings 0..10⁹, distances 0..10⁹, and an open flag of 0 or 1.
Output
Output at most K 0-based indices in ranking order; if there are no results, output an empty line.
Example 1
Input:
4 2
90 4 1
95 8 0
90 2 1
85 1 1
Output:
2 0
Example 2
Input:
3 5
80 3 1
80 2 1
90 10 1
Output:
2 1 0
Example 3
Input:
1 1
10 1 0
Output:
Example notes
Example 1: index 1 is closed, and 2 and 0 have the same rating but 2 is closer, so output 2 0. Example 2: only 3 merchants are open, so return all of them: 2 1 0. Example 3: no merchant is open, so output an empty line.
Editorial
Loading solution…