fork download
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int main() {
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(nullptr);
  10.  
  11. int t;
  12. cin >> t;
  13. while (t--) {
  14. int n;
  15. cin >> n;
  16. vector<int> a(n);
  17. unordered_map<int, int> freq;
  18. int max_freq = 0;
  19. for (int &x : a) {
  20. cin >> x;
  21. freq[x]++;
  22. max_freq = max(max_freq, freq[x]);
  23. }
  24.  
  25. if (n == 2) {
  26. cout << "NO\n";
  27. continue;
  28. }
  29.  
  30. bool found = false;
  31.  
  32. for (auto &p : freq) {
  33. if (p.second >= 2) {
  34. int median_candidate = p.first;
  35. int L = 0, E = p.second, G = 0;
  36.  
  37. for (auto &q : freq) {
  38. if (q.first < median_candidate)
  39. L += q.second;
  40. else if (q.first > median_candidate)
  41. G += q.second;
  42. }
  43.  
  44. if (n >= 4) {
  45. found = true;
  46. break;
  47. } else if (n == 3) {
  48. if (L == 0 && G >= 1) {
  49. // Sample Input 2: YES
  50. found = true;
  51. break;
  52. } else if (G == 0 && L >= 1) {
  53. // User's Counterexample: NO
  54. found = false;
  55. break;
  56. } else if (L >= 1 && G >= 1) {
  57. found = true;
  58. break;
  59. }
  60. }
  61. }
  62. }
  63.  
  64. cout << (found ? "YES\n" : "NO\n");
  65. }
  66. return 0;
  67. }
  68.  
Success #stdin #stdout 0s 5284KB
stdin
3
2
2 1
3
2 3 2
6
6 4 3 9 3 3
stdout
NO
YES
YES