#include <stdio.h> #define MAX 201719 int tab[MAX] = {}; inline int max(int a, int b){ if(a > b){return a;} return b; } int main(){ int n, i, a, maximum = -1, value = -1; scanf("%d", &n); for(i = n; i > 0; --i){ scanf("%d", &a); maximum = max(maximum, a); tab[a]++; } value = maximum; for(i = 0; i < maximum; i++){ tab[i+1] += tab[i] >> 1; } i = maximum; while(tab[i] != 0){ tab[i+1] += tab[i] >> 1; if(tab[i+1] == 0) { break;} i++; } printf("%d", i); 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 | #include <stdio.h> #define MAX 201719 int tab[MAX] = {}; inline int max(int a, int b){ if(a > b){return a;} return b; } int main(){ int n, i, a, maximum = -1, value = -1; scanf("%d", &n); for(i = n; i > 0; --i){ scanf("%d", &a); maximum = max(maximum, a); tab[a]++; } value = maximum; for(i = 0; i < maximum; i++){ tab[i+1] += tab[i] >> 1; } i = maximum; while(tab[i] != 0){ tab[i+1] += tab[i] >> 1; if(tab[i+1] == 0) { break;} i++; } printf("%d", i); return 0; } |