Problem
“You won’t get caught if you hide behind someone.”
Sang-Woo advises Gi-Hun to hide behind someone to avoid getting shot.
Gi-Hun follows Sang-Woo's advice and hides behind Ali, who saved his life earlier. Gi-Hun and Ali both have the same height, . Many players saw this trick and also started hiding behind Ali.
Now, there are players standing between Gi-Hun and Ali in a straight line, with the player having height . Gi-Hun wants to know the minimum number of players who need to get shot so that Ali is visible in his line of sight.
Note:
- Line of sight is a straight line drawn between the topmost point of two objects. Ali is visible to Gi-Hun if nobody between them crosses this line.
- Even if there are some players who have the same height as that of Gi-Hun and Ali, Ali will be visible in Gi-Hun's line of sight.
- Gi-Hun and Ali have the same height.
Input Format
- The first line of 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 two space-separated integers and , denoting the total number of players between Gi-Hun and Ali and the height of both of them respectively.
- The second line of each test case contains space-separated integers, denoting the heights of the players between Gi-Hun and Ali.
Output Format
For each test case, output in a single line the minimum number of players who need to get shot so that Ali is visible in Gi-Hun's line of sight.
Constraints
- for every .
- The sum of across all test cases does not exceed .
Sample 1:
3 4 10 2 13 4 16 5 8 9 3 8 8 4 4 6 1 2 3 4
2 1 0
Explanation:
Test Case 1: Gi-Hun and Ali have height . For Ali to be visible to Gi-Hun, the second person (with height ) and the fourth person (with height ) need to get shot. Hence, the minimum number of players who need to get shot is .
Test Case 2: Gi-Hun and Ali have height . For Ali to be visible to Gi-Hun, the first person (with height ) needs to get shot. Hence, the minimum number of players who need to get shot is .
Test Case 3: Nobody needs to get shot because everyone is shorter than Gi-Hun and Ali.
#include <iostream>
using namespace std;
int main() {
int t ;
cin>>t;
while(t>0){
int n,k;
cin>>n;
cin>>k;
int arr[n];
for (int i = 0; i < n; i++) {
cin>>arr[i];
}
int s = 0;
for (int j = 0; j < n; j++) {
if(arr[j]>k){
s = s+1;
}
}
cout<<s<<endl;
t = t-1;
}
return 0;
}
0 Comments