-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path1077E. Thematic Contests.cpp
51 lines (43 loc) · 1.21 KB
/
1077E. Thematic Contests.cpp
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
/*
Idea:
- Try all possible starting values from 1 to `max(a[i])`.
- This solution work in ~ `20 * 2*10^5`.
- To figure why, the smallest starting number is 1
and in each iteration it should be multiplied by 2,
so in 18 steps it will reach 262144 which is greater than
the number of elements in the array.
*/
#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 1;
int n, a[N], fr[N];
vector<int> all;
int main() {
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%d", a + i), all.push_back(a[i]);
sort(all.begin(), all.end());
all.resize(unique(all.begin(), all.end()) - all.begin());
for(int i = 0; i < n; ++i)
a[i] = lower_bound(all.begin(), all.end(), a[i]) - all.begin(),
++fr[a[i]];
all.clear();
for(int i = 0; i < N; ++i)
if(fr[i] != 0)
all.push_back(fr[i]);
sort(all.begin(), all.end());
int res = 0, tmp, idx, cur;
for(int i = 1; i <= all.back(); ++i) {
tmp = 0, idx = -1, cur = i;
while(true) {
idx = lower_bound(all.begin() + idx + 1, all.end(), cur) - all.begin();
if(idx == all.size())
break;
tmp += cur;
cur += cur;
}
res = max(res, tmp);
}
printf("%d\n", res);
return 0;
}