New start day 7: 06/10/2020 Codechef October Long REPLESX
Replace for X
You are given an array of integers and three more integers and .
An operation on the array is defined to be: replace the -th smallest integer in the array with any integer you want.
Output the minimum number of operations you must perform on the array (possibly operations) to make the -th smallest element of the array equal to . If it is impossible to do so output .
Note: the -th smallest number in an array is the -th number from the left when the array is sorted in non-decreasing order.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains four integers respectively.
- The second line contains space-separated integers
Output
For each test case, print a single line containing one integer ― the minimum number of operations you must perform to make the -th smallest element or if its impossible to do so.
Constraints
- The sum of over all test cases does not exceed
- for each valid
Subtasks
Subtask #1 (10 points):
Subtask #2 (40 points): The sum of over all test cases does not exceed
Subtask #3 (50 points): Original constraints
Example Input
2
5 4 3 4
4 9 7 0 8
2 25 1 2
100 20
Example Output
1
-1
Explanation
Example case 1:
- We can perform one operation in the array. Take the -th smallest integer of the current array (which is in this case) and replace it with . The array then becomes which now makes as the 3rd smallest number of the array.
Example case 2:
- It is impossible to make as the smallest number of the array.
Comments
Post a Comment