#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio( false );
int n = 0;
cin >> n;
map<int,int> values;
while(n--)
{
int v = 0;
cin >> v;
auto it = values.insert({v, 1});
if (!it.second)
it.first->second += 1;
}
auto it = values.begin();
while(*it != *values.rbegin())
{
int q = it->second;
int v = it->first;
auto tr = values.insert({v+1, q/2});
if (!tr.second)
tr.first->second += q/2;
it = tr.first;
}
int r = it->first;
while(it->second /= 2)
r++;
printf("%d\n", r);
return 0;
}
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 | #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio( false ); int n = 0; cin >> n; map<int,int> values; while(n--) { int v = 0; cin >> v; auto it = values.insert({v, 1}); if (!it.second) it.first->second += 1; } auto it = values.begin(); while(*it != *values.rbegin()) { int q = it->second; int v = it->first; auto tr = values.insert({v+1, q/2}); if (!tr.second) tr.first->second += q/2; it = tr.first; } int r = it->first; while(it->second /= 2) r++; printf("%d\n", r); return 0; } |
English