
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 256 megabytes
You are given an array containing scores across different players in an Olympics sport. A higher score is desired in some sports, whereas in some sports, a lower score is desired (It is denoted by d, which can be 1 or 0). You have to find the kth Best Athlete.
Note that it is the k
th Best Athlete in the sorted order, not the k
th ‘distinct’ Best Athlete not in a distinct order.
Constraints: You are not allowed to use inbuilt sorting algorithms. (should be obvious)
Hint: Also there is a strict constraint on time and space, so you have to sort in O(nlogn) and in place only.
The first line contains three integers t, k, d denoting the number of players, the k
th best score we need to find and d (1 or 0) where 1 denotes higher score is better, and 0 denotes lower score is better. ( 0 <= k <= t <= 10^5 )
The second line contains t space-separated integers indicating the player’s scores.
Output the single integer, representing the respective score. See sample cases for example.
standard input standard output 10 3 1 1 2 3 4 5 6 7 8 9 10
Page 1 of 1