fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=998244353;
  5.  
  6. void solve() {
  7.  
  8. int n;
  9. cin >> n;
  10. vector<int> a(n);
  11. for(int i=0;i<n;i++) cin >> a[i];
  12. sort(a.begin(),a.end());
  13.  
  14. int ans = 2;
  15. int l=0,r=2;
  16. while(l<r-1 && r<n){
  17. while(a[l]+a[l+1]<=a[r] && l<r-1) l++;
  18. ans=max(ans,r-l+1);
  19. r++;
  20. }
  21.  
  22. cout << n-ans << '\n';
  23. }
  24.  
  25. int main(){
  26. ios::sync_with_stdio(false);
  27. cin.tie(nullptr);
  28.  
  29. int t;
  30. cin >> t;
  31. while (t--) solve();
  32.  
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 5316KB
stdin
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
stdout
3
1
0
8