#K66292. Top K Books
Top K Books
Top K Books
You are given a collection of books with their corresponding sales figures. Your task is to determine the indices of the top K books having the highest sales. In case two books have the same sales, the book with the smaller index is ranked higher.
Formally, given integers \(N\) and \(K\) and an array \(sales\) of length \(N\), you need to find \(K\) indices \(i_1, i_2, \ldots, i_K\) such that the corresponding sales are in non-increasing order. In mathematical terms, let \(S[i]\) denote the sales of the \(i^{th}\) book. Then for the selected indices, we should have:
[ S[i_1] \geq S[i_2] \geq \cdots \geq S[i_K] ]
and if \(S[i] = S[j]\) and \(i < j\), then index \(i\) should come before index \(j\) in the result.
inputFormat
The input is read from standard input (stdin) and consists of two lines. The first line contains two space-separated integers \(N\) and \(K\): the number of books and the number of books to select, respectively. The second line contains \(N\) space-separated integers representing the sales figures for each book.
outputFormat
Print the indices of the top \(K\) books on a single line, separated by spaces. The order should reflect the descending order of sales, and in case of ties, the smaller index comes first.
## sample5 3
150 200 200 80 120
1 2 0