-
Notifications
You must be signed in to change notification settings - Fork 0
/
SNACKQL19_QUALPREL_2.cpp
64 lines (57 loc) · 1019 Bytes
/
SNACKQL19_QUALPREL_2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<bits/stdc++.h>
using namespace std;
const int sz = 100010;
int arr[sz];
int test;
int k, n;
int val;
int ans;
int binarySearch(int lo, int hi)
{
if(lo > hi)
{
return 0;
}
else
{
int mid = (lo+hi)/2;
if(arr[mid] == val)
{
return mid; // since we need to add mid-k to the answer
}
else if(arr[mid] < val)
{
return binarySearch(lo, mid-1);
}
else
{
return binarySearch(mid+1, hi);
}
}
}
int main()
{
arr[0] = INT_MAX;
scanf("%d", &test);
while(test--)
{
scanf("%d%d", &n, &k);
for(int i=1; i<=n; i++)
{
scanf("%d", &arr[i]);
}
sort(arr+1, arr+n+1, greater<int>());
ans = k;
val = arr[k];
do
{
k++;
} while(val == arr[k]);
if(k-ans > 1)
{
ans = k-1;
}
printf("%d\n", ans);
}
return 0;
}