#include <bits/stdc++.h> #define MAX 201718 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int k, n, x; vector<int> v(MAX + 1, 0); cin >> n; while (n--) { cin >> x; v[x]++; } for (int i = 0; i < MAX; i++) v[i + 1] += v[i] / 2; for (k = MAX; v[k] == 0; k--) ; cout << ((k != MAX) ? k : k + (int)log2(v[k])) << "\n"; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <bits/stdc++.h> #define MAX 201718 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int k, n, x; vector<int> v(MAX + 1, 0); cin >> n; while (n--) { cin >> x; v[x]++; } for (int i = 0; i < MAX; i++) v[i + 1] += v[i] / 2; for (k = MAX; v[k] == 0; k--) ; cout << ((k != MAX) ? k : k + (int)log2(v[k])) << "\n"; return 0; } |