Trinity

C. Trinity

You are given an array a a a of n n n elements a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,,an.

You can perform the following operation any number (possibly 0 0 0) of times:

  • Choose two integers i i i and j j j, where 1 ≤ i , j ≤ n 1 \le i, j \le n 1i,jn, and assign a i : = a j a_i := a_j ai:=aj.

Find the minimum number of operations required to make the array a a a satisfy the condition:

  • For every pairwise distinct triplet of indices ( x , y , z ) (x, y, z) (x,y,z) ( 1 ≤ x , y , z ≤ n 1 \le x, y, z \le n 1x,y,zn, x ≠ y x \ne y x=y, y ≠ z y \ne z y=z, x ≠ z x \ne z x=z), there exists a non-degenerate triangle with side lengths a x a_x ax, a y a_y ay and a z a_z az, i.e. a x + a y > a z a_x + a_y > a_z ax+ay>az, a y + a z > a x a_y + a_z > a_x ay+az>ax and a z + a x > a y a_z + a_x > a_y az+ax>ay.

Input

Each test consists of multiple test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n n n ( 3 ≤ n ≤ 2 ⋅ 1 0 5 3 \le n \le 2 \cdot 10^5 3n2105) — the number of elements in the array a a a.

The second line of each test case contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,,an ( 1 ≤ a i ≤ 1 0 9 1 \le a_i \le 10^9 1ai109) — the elements of the array a a a.

It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

Output

For each test case, output a single integer — the minimum number of operations required.

Example

Input

4
7
1 2 3 4 5 6 7
3
1 3 2
3
4 5 3
15
9 3 8 1 6 5 3 8 2 1 4 2 9 4 7

Output

3
1
0
8

Note

In the first test case, one of the possible series of operations would be:

  • Assign a 1 : = a 4 = 4 a_1 := a_4 = 4 a1:=a4=4. The array will become [ 4 , 2 , 3 , 4 , 5 , 6 , 7 ] [4, 2, 3, 4, 5, 6, 7] [4,2,3,4,5,6,7].
  • Assign a 2 : = a 5 = 5 a_2 := a_5 = 5 a2:=a5=5. The array will become [ 4 , 5 , 3 , 4 , 5 , 6 , 7 ] [4, 5, 3, 4, 5, 6, 7] [4,5,3,4,5,6,7].
  • Assign a 7 : = a 1 = 4 a_7 := a_1 = 4 a7:=a1=4. The array will become [ 4 , 5 , 3 , 4 , 5 , 6 , 4 ] [4, 5, 3, 4, 5, 6, 4] [4,5,3,4,5,6,4].

It can be proven that any triplet of elements with pairwise distinct indices in the final array forms a non-degenerate triangle, and there is no possible answer using less than 3 3 3 operations.

In the second test case, we can assign a 1 : = a 2 = 3 a_1 := a_2 = 3 a1:=a2=3 to make the array a = [ 3 , 3 , 2 ] a = [3, 3, 2] a=[3,3,2].

In the third test case, since 3 3 3, 4 4 4 and 5 5 5 are valid side lengths of a triangle, we don’t need to perform any operation to the array.

code

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
 
using namespace std;


const int N = 2e5+10,INF=0x3f3f3f3f,mod=1e9+7;
 
typedef pair<int,int> PII;

int T=1;

void solve(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	int l=0,ans=INF;
	for(int r=2;r<n;r++){
		while(a[l]+a[l+1]<=a[r]){
			l++;
		}
		ans=min(ans,l+n-r-1);
	}
	cout<<ans<<endl;
}

signed main(){
	cin>>T; 
    while(T--){
        solve();
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值