-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1890A.cpp
More file actions
56 lines (45 loc) · 991 Bytes
/
1890A.cpp
File metadata and controls
56 lines (45 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// coded by Cocane
#include <bits/stdc++.h>
#define ll long long
#define forn(i, n) for (int i = 0; i < n; i++)
#define read(a) for (auto &i : a) cin >> i
using namespace std;
typedef vector<int> vi;
void solve() {
int n;
cin >> n;
vi v(n);
read(v);
if (n == 2) {
cout << "Yes" << endl;
return;
}
unordered_map<int, int> freq;
for (int i = 0; i < n; i++) {
freq[v[i]]++;
}
if (freq.size() > 2) {
cout << "No" << endl;
return;
}
if (freq.size() == 2) {
auto it = freq.begin();
int val1 = it->second;
int val2 = (++it)->second;
if (abs(val1 - val2) > 1) {
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}