#include <iostream> #define MAX_A 201720 int a[MAX_A]; int main() { int n, aa, res, minc=MAX_A, maxc=0; std::ios::sync_with_stdio(false); std::cin >> n; while(n--) { std::cin >> aa; a[aa]++; minc = (minc < aa ? minc : aa); maxc = (maxc < aa ? aa : maxc); } for(int i=minc+1; i<maxc+1; i++) { a[i] += (a[i-1] >> 1); } res = maxc; while(a[maxc] > 1) { res++; a[maxc] >>= 1; } std::cout << res << std::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 | #include <iostream> #define MAX_A 201720 int a[MAX_A]; int main() { int n, aa, res, minc=MAX_A, maxc=0; std::ios::sync_with_stdio(false); std::cin >> n; while(n--) { std::cin >> aa; a[aa]++; minc = (minc < aa ? minc : aa); maxc = (maxc < aa ? aa : maxc); } for(int i=minc+1; i<maxc+1; i++) { a[i] += (a[i-1] >> 1); } res = maxc; while(a[maxc] > 1) { res++; a[maxc] >>= 1; } std::cout << res << std::endl; return 0; } |