The K-th lowest score
Statement
N players took part in a board game tournament and received a final score. The scores are tallied as integers, and a player who piled up penalties can end with a negative score. Several players can also receive the same score.
The organizers want to know the score that sits K-th from the front when the players' scores are laid out from the lowest to the highest.
Given the scores of the N players and K, write a program that prints the score sitting K-th from the front when the scores are laid out from the lowest.
For example, suppose the scores of N=5 players are as in the table below and K=2.
| Player | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Score | 4 | 1 | 2 | 3 | 5 |
Laying the scores out from the lowest gives the following.
| Order | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Score | 1 | 2 | 3 | 4 | 5 |
| Player | 2 | 3 | 4 | 1 | 5 |
The score sitting 2nd from the front is 2, so the answer in this case is 2.
Even when the same score appears several times, each one is counted on its own. For example, suppose the scores of N=4 players are 7, 3, 7, 3. Laying them out from the lowest gives 3, 3, 7, 7.
| Order | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| Score | 3 | 3 | 7 | 7 |
If K=3 here, the score sitting 3rd from the front is 7. In other words, the distinct scores are not picked out and counted. Among the N values laid out from the lowest, the K-th value from the front is printed as it is.
K takes a value from 1 to N. When K=1 the lowest score is printed, and when K=N the highest score is printed. There can also be very many players, so it is better to read all the scores at once and then sort them a single time.
Input and Output Examples
Example 1
Input
5 2 4 1 2 3 5
Output
2
Example 2
Input
10 6 -168384455 247198315 577132058 -404633708 -179564237 -279546414 -688948127 -674478692 -965644886 486949094
Output
-179564237
Example 3
Input
5 5 5 4 3 2 1
Output
5
Input
First, the first line gives the number of players N and K, separated by one space. N is a natural number between 1 and 5,000,000, and K is a natural number between 1 and N.
Next, the second line gives the scores of the N players from player 1 to player N in order, separated by one space. Each score is an integer whose absolute value is at most 1,000,000,000.
Output
Print the score sitting K-th from the front when the scores are laid out from the lowest, on one line. Do not attach a space after the value, and finish with one line break.
Requirements
- Read the input from standard input and write the result to standard output
- Lay the scores out from the lowest and find the K-th value from the front
- When the same score appears several times, count each one on its own
- Print one value only, on one line
- There are very many players, so reading the whole input at once is better
- You must write a program that reads from standard input and writes to standard output
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
- There are 17 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 17 cases to solve this.
Examples
3 public cases. Judging also uses hidden cases. You have to pass all 17 cases to solve this.
5 2 4 1 2 3 5
2
10 6 -168384455 247198315 577132058 -404633708 -179564237 -279546414 -688948127 -674478692 -965644886 486949094
-179564237
5 5 5 4 3 2 1
5
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 3 public cases. Submitting runs the hidden cases too.
People who solved this problem
Nobody yet. You could be the first.