#include <iostream> using namespace std; #define Int long long int #define MAX_EXP 201718 #define DEBUG(x) int main() { ios::sync_with_stdio(false); DEBUG(cout << "Podaj n:\n";) int n; cin >> n; DEBUG(cout << "Podaj wykladniki:\n";) Int tab[MAX_EXP + 1]; for (auto i = 0; i < MAX_EXP + 1; ++i) tab[i] = 0; int in_val; int in_max = 0; for (auto i = 0; i < n; ++i) { cin >> in_val; ++tab[in_val]; if (in_val > in_max) { in_max = in_val; } } for (auto i = 1; i < in_max; ++i) { if (tab[i] > 1) { tab[i + 1] += tab[i] / 2; } } Int cnt = tab[in_max]; Int max_val = in_max; while(cnt > 1) { cnt /= 2; ++max_val; } cout << max_val << endl; 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 <iostream> using namespace std; #define Int long long int #define MAX_EXP 201718 #define DEBUG(x) int main() { ios::sync_with_stdio(false); DEBUG(cout << "Podaj n:\n";) int n; cin >> n; DEBUG(cout << "Podaj wykladniki:\n";) Int tab[MAX_EXP + 1]; for (auto i = 0; i < MAX_EXP + 1; ++i) tab[i] = 0; int in_val; int in_max = 0; for (auto i = 0; i < n; ++i) { cin >> in_val; ++tab[in_val]; if (in_val > in_max) { in_max = in_val; } } for (auto i = 1; i < in_max; ++i) { if (tab[i] > 1) { tab[i + 1] += tab[i] / 2; } } Int cnt = tab[in_max]; Int max_val = in_max; while(cnt > 1) { cnt /= 2; ++max_val; } cout << max_val << endl; return 0; } |