#include <cstdio> #include <vector> int main() { const int MAXA = 201728; std::vector<int> c(MAXA, 0); int n; scanf("%d", &n); int ci; int maxCi = -1; for(int i = 0; i < n; i++) { scanf("%d", &ci); c[ci]++; if(maxCi < ci) { maxCi = ci; } } int curr = 0; for(int i = 0; i < maxCi; i++) { curr = (curr + c[i])/2; } curr += c[maxCi]; while(curr > 1) { maxCi++; curr /= 2; } printf("%d\n", maxCi); }
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 | #include <cstdio> #include <vector> int main() { const int MAXA = 201728; std::vector<int> c(MAXA, 0); int n; scanf("%d", &n); int ci; int maxCi = -1; for(int i = 0; i < n; i++) { scanf("%d", &ci); c[ci]++; if(maxCi < ci) { maxCi = ci; } } int curr = 0; for(int i = 0; i < maxCi; i++) { curr = (curr + c[i])/2; } curr += c[maxCi]; while(curr > 1) { maxCi++; curr /= 2; } printf("%d\n", maxCi); } |