#include <iostream> const unsigned MAX_EXP = 201719; unsigned buckets[MAX_EXP]; int main() { unsigned n; unsigned input; scanf("%u", &n); for (unsigned i = 0; i < n; i++) { scanf("%u", &input); buckets[input]++; } unsigned maxi = 0; for (unsigned i = 0; i < MAX_EXP - 1; i++) { if (buckets[i] > 0) maxi = i; buckets[i + 1] += buckets[i] / 2; } if (buckets[MAX_EXP - 1] > 0) { maxi = MAX_EXP - 1; while (buckets[MAX_EXP - 1] > 1) { buckets[MAX_EXP - 1] /= 2; maxi++; } } printf("%u", maxi); }
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> const unsigned MAX_EXP = 201719; unsigned buckets[MAX_EXP]; int main() { unsigned n; unsigned input; scanf("%u", &n); for (unsigned i = 0; i < n; i++) { scanf("%u", &input); buckets[input]++; } unsigned maxi = 0; for (unsigned i = 0; i < MAX_EXP - 1; i++) { if (buckets[i] > 0) maxi = i; buckets[i + 1] += buckets[i] / 2; } if (buckets[MAX_EXP - 1] > 0) { maxi = MAX_EXP - 1; while (buckets[MAX_EXP - 1] > 1) { buckets[MAX_EXP - 1] /= 2; maxi++; } } printf("%u", maxi); } |