-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighfreq.cpp
More file actions
36 lines (35 loc) · 756 Bytes
/
highfreq.cpp
File metadata and controls
36 lines (35 loc) · 756 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
#include <bits/stdc++.h>
#define ln long long
using namespace std;
int main()
{
// your code goes here
ln num;
cin >> num;
while (num--)
{
ln num1, m, n, flag, post;
cin >> num1;
ln arr[num1 + 1] = {0};
for (m = 0; m < num1; m++)
{
cin >> flag;
arr[flag]++;
}
for (m = 0; m < 2; m++)
{
for (n = 0; n < num1; n++)
{
if (arr[n] > arr[n + 1])
swap(arr[n], arr[n + 1]);
}
}
if (arr[num1] % 2)
post = arr[num1] / 2 + 1;
else
post = arr[num1] / 2;
cout << max(arr[num1 - 1], post)
<< "\n";
}
return 0;
}