Array and Swaps

mail@pastecode.io avatar
unknown
c_cpp
a year ago
778 B
10
Indexable
Never
#include <bits/stdc++.h>
using namespace std;

#define ll int64_t
#define endl '\n'

const int mx_value = 1e6;
void solve() {
    int n;
    cin >> n;
    int cnt[mx_value + 10] = {}; // initialised to 0.

    int mx_frequency = 1; // initially set to 1.

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        cnt[x]++;
        mx_frequency = max(mx_frequency, cnt[x]);
    }

    if (mx_frequency > (n + 1) / 2) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
    }
}
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);


    int t = 1;
    // int i = 1;
    // cin >> t;
    while (t--) {
        // cout << "Case #" << i << ": ";
        solve();
        // i++;
    }
    return 0;
}