-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmajor.cpp
More file actions
42 lines (40 loc) · 749 Bytes
/
major.cpp
File metadata and controls
42 lines (40 loc) · 749 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
#include <iostream>
#include <cstring> //memset
#include <algorithm>
#include <bitset>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <queue>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
int main() {
freopen("input.txt", "r", stdin);
bool flagged;
int test_cases, n, x, res, count[2010];
cin >> test_cases;
while (test_cases--) {
flagged = false;
memset(count, 0, sizeof(count));
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x;
count[x+1000]++;
}
for (int i = 0; i < 2010; ++i) {
if (count[i] > n/2) {
flagged = true;
res = i-1000;
}
}
if (flagged)
cout << "YES " << res << endl;
else
cout << "NO" << endl;
}
return 0;
}