#include <iostream>
using namespace std;
const int MAXW = 201718;
int licz[MAXW + 5];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int maks = 0;
for (int i = 0; i < n; i++)
{
int a;
cin >> a;
licz[a]++;
if (maks < a)
maks = a;
}
int p = 0;
for (int i = 0; i < maks + 1; i++)
{
licz[i] += p;
p = licz[i] / 2;
}
while (p > 0)
{
p /= 2;
maks++;
}
cout << maks << "\n";
}
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 | #include <iostream> using namespace std; const int MAXW = 201718; int licz[MAXW + 5]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int maks = 0; for (int i = 0; i < n; i++) { int a; cin >> a; licz[a]++; if (maks < a) maks = a; } int p = 0; for (int i = 0; i < maks + 1; i++) { licz[i] += p; p = licz[i] / 2; } while (p > 0) { p /= 2; maks++; } cout << maks << "\n"; } |
English