Finding the Kth Best Athlete in Sorted Scores, Assignments of Programming for Engineers

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

2020/2021

Uploaded on 07/04/2021

nikhil-gupta-15
nikhil-gupta-15 🇮🇳

2 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
kth Best Athlete
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 kth Best Athlete in the sorted order, not the kth ‘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.
Input
The first line contains three integers t,k,ddenoting the number of players, the kth 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 <= 105)
The second line contains tspace-separated integers indicating the player’s scores.
Output
Output the single integer, representing the respective score. See sample cases for example.
Examples
standard input standard output
10 3 1
12345678910
8
10 3 0
12345678910
3
511
43314
4
Page 1 of 1

Partial preview of the text

Download Finding the Kth Best Athlete in Sorted Scores and more Assignments Programming for Engineers in PDF only on Docsity!

kth Best Athlete

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.

Input

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

Output the single integer, representing the respective score. See sample cases for example.

Examples

standard input standard output 10 3 1 1 2 3 4 5 6 7 8 9 10

Page 1 of 1