#K64992. Insert Participant Score Position
Insert Participant Score Position
Insert Participant Score Position
You are given a list of scores of participants, sorted in non-increasing order. When a new participant with score \(X\) is added, determine the 1-indexed position in which \(X\) should be inserted so that the list remains sorted in non-increasing order.
More formally, let \(B = [b_1, b_2, \dots, b_M]\) be the list of scores where \(b_i \ge b_{i+1}\). The position \(P\) for a new score \(X\) is given by:
[ P = #{b_i \mid b_i \ge X} + 1 ]
You need to process multiple test cases. For each test case, read the scores and the new participant's score and then print the corresponding position where the new score fits in.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer \(T\) representing the number of test cases.
- For each test case, there are three lines:
- The first line contains an integer \(M\), the number of existing participants.
- The second line contains \(M\) space-separated integers representing the scores in non-increasing order. (If \(M\) is 0, this line will be empty.)
- The third line contains an integer \(X\), the new participant's score.
outputFormat
For each test case, output a single integer on a new line, which is the 1-indexed position where the new participant's score \(X\) fits in the sorted order. The output is written to stdout.
## sample5
4
100 90 90 80
85
5
50 50 50 50 50
50
1
30
40
3
100 90 80
75
3
70 70 70
70
4
6
1
4
4
</p>