#include <bits/stdc++.h> using namespace std; int shr(int a, int k) { return k < 30 ? (a >> k) : 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); map<int, int> cc; int n; cin >> n; for(int i = n; i --> 0;) { int a; cin >> a; cc[a]++; } int pc, pe; { map<int, int>::iterator it = cc.begin(); pc = it->second; pe = it->first; for(it++; it != cc.end(); it++) { pc = shr(pc, it->first - pe) + it->second; pe = it->first; } } while(pc >= 2) { pe++; pc >>= 1; } cout << pe << '\n'; 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 shr(int a, int k) { return k < 30 ? (a >> k) : 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); map<int, int> cc; int n; cin >> n; for(int i = n; i --> 0;) { int a; cin >> a; cc[a]++; } int pc, pe; { map<int, int>::iterator it = cc.begin(); pc = it->second; pe = it->first; for(it++; it != cc.end(); it++) { pc = shr(pc, it->first - pe) + it->second; pe = it->first; } } while(pc >= 2) { pe++; pc >>= 1; } cout << pe << '\n'; return 0; } |