
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A problem where you are given an array of scores from athletes in an olympics sport and need to find the kth best score. The challenge is to sort the array in-place and in o(nlogn) time without using built-in sorting algorithms. The document also mentions that higher scores are desired in some sports and lower scores in others, denoted by the variable d.
Typology: Assignments
1 / 1
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