-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheights.cpp
More file actions
47 lines (46 loc) · 989 Bytes
/
heights.cpp
File metadata and controls
47 lines (46 loc) · 989 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
#include <bits/stdc++.h>
#define ln long long
using namespace std;
int main()
{
// your code goes here
int num1, num, maxi, output, flag;
cin >> num1;
while (num1--)
{
cin >> num;
vector<int> htg(num, 0);
unordered_map<int, int> post;
maxi = 0;
for (int h = 0; h < num; h++)
{
cin >> htg[h];
post[htg[h]]++;
maxi = max(maxi, htg[h]);
}
output = 0, flag = 0;
for (auto h : post)
{
if (h.second == 1)
output++;
flag = max(flag, h.second);
}
if (output % 2)
{
int s = (output + 1) / 2;
if (post[maxi] == 1)
{
if (flag == 2)
s++;
}
cout << s << "\n";
}
else
{
int s = output / 2;
cout << s
<< "\n";
}
}
return 0;
}