1 | //https://xinyoudui.com/ac/contest/7450060E90006AA04E2FBE6/problem/9897 |
2 | #include<bits/stdc++.h> |
3 | using namespace std; |
4 | const int N=2e5+10; |
5 | bool f(int a[],int n,int k,int mid) |
6 | { |
7 | int cnt=0; |
8 | for(int i=0;i<n;i++) |
9 | { |
10 | cnt+=min(a[i],mid); |
11 | } |
12 | return cnt>=mid*k; |
13 | } |
14 | int fun(int a[],int n,int k) |
15 | { |
16 | int L=0,R=1e9; |
17 | int res=0; |
18 | while(L<=R) |
19 | { |
20 | int mid=(L+R)>>1; |
21 | if(f(a,n,k,mid)) |
22 | { |
23 | res=mid; |
24 | L=mid+1; |
25 | } |
26 | else |
27 | { |
28 | R=mid-1; |
29 | } |
30 | } |
31 | return res; |
32 | } |
33 | int main() |
34 | { |
35 | int t; |
36 | cin>>t; |
37 | while(t--) |
38 | { |
39 | int n,k; |
40 | cin>>n>>k; |
41 | int a[N]; |
42 | for(int i=0;i<n;i++) |
43 | { |
44 | cin>>a[i]; |
45 | } |
46 | int ans=fun(a,n,k); |
47 | cout<<ans<<endl; |
48 | } |
49 | return 0; |
50 | } |