fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define endl '\n'
  4. #define int long long
  5.  
  6. const int MOD = 1e9 + 7;
  7. const int INF = LLONG_MAX / 2;
  8.  
  9. signed main() {
  10. ios::sync_with_stdio(false);
  11. cin.tie(NULL);
  12.  
  13. int t;
  14. cin >> t;
  15. while (t--) {
  16. int n;
  17. cin>>n;
  18. vector<int>arr(n);
  19. for(int i=0;i<n;i++){
  20. cin>>arr[i];
  21. }
  22. sort(arr.begin(),arr.end());
  23. int fir=arr[0];
  24. int las=arr[n-1];
  25. int cnt1=0;
  26. int cnt2=0;
  27. for(int i=0;i<n;i++){
  28. if(arr[i] == fir)cnt1++;
  29. if(arr[i] == las)cnt2++;
  30. }
  31. if((cnt1 >= n/2) && (cnt2 >=n/2))cout<<"YES"<<endl;
  32. else cout<<"NO"<<endl;
  33. }
  34.  
  35. }
Success #stdin #stdout 0s 5288KB
stdin
5
2
8 9
3
1 1 2
4
1 1 4 5
5
2 3 3 3 3
4
100000 100000 100000 100000
stdout
YES
YES
NO
NO
YES