#include <bits/stdc++.h> using namespace std; const int32_t MAX_N = 1000006; int32_t nom[MAX_N]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int32_t a, i = 0; i < n; ++i) { cin >> a; nom[a]++; } int32_t ost = 0; for (int32_t i = 0; i < MAX_N; ++i) { if (nom[i] > 0) { ost = i; nom[i+1] += (nom[i] / 2); } } cout << ost; 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 | #include <bits/stdc++.h> using namespace std; const int32_t MAX_N = 1000006; int32_t nom[MAX_N]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int32_t a, i = 0; i < n; ++i) { cin >> a; nom[a]++; } int32_t ost = 0; for (int32_t i = 0; i < MAX_N; ++i) { if (nom[i] > 0) { ost = i; nom[i+1] += (nom[i] / 2); } } cout << ost; return 0; } |