-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1665B.cpp
More file actions
45 lines (38 loc) · 776 Bytes
/
1665B.cpp
File metadata and controls
45 lines (38 loc) · 776 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long t;
cin >> t;
while (t--)
{
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; i++)
cin >> a[i];
map<long long, long long> mp;
for (long long i = 0; i < n; i++)
mp[a[i]]++;
long long current_highest_freq = 0;
for (auto i : mp)
current_highest_freq = max(current_highest_freq, i.second);
long long operations = 0;
while (current_highest_freq < n)
{
operations++;
if (current_highest_freq * 2 <= n)
{
operations += current_highest_freq;
current_highest_freq *= 2;
}
else
{
operations += n - current_highest_freq;
current_highest_freq = n;
}
}
cout << operations << endl;
}
return 0;
}