lina_os

Untitled

Dec 19th, 2024 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <algorithm>
  4. #include <string>
  5. #include <map>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  12. int n;
  13. cin >> n;
  14. int arr[n];
  15. int freq[1000]={};
  16. for (int i=0; i<n; i++) {
  17. cin >> arr[i];
  18. freq[arr[i]]++;
  19. }
  20. int mx=0;
  21. int mxIdx=0;
  22. long long sum=0;
  23. for (int i=0; i<1000; i++) {
  24. if (freq[i]>mx) mxIdx=i;
  25. mx = max (mx, freq[i]);
  26. sum += freq[i];
  27. }
  28. sum -= freq[mxIdx];
  29. if (sum < mx-1) cout << "NO";
  30. else cout << "YES";
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment