#include <iostream> int main() { int n; std::cin >> n; int *tab = new int[202000]; int j = 0; for(int i = 0; i < n; i++) { std::cin >> j; ++tab[j]; } int max = 0; for(int i = 0; i < 202000; i++) { tab[i+1] += tab[i] / 2; if(tab[i+1]) max = i+1; } std::cout << max << std::endl; delete [] tab; }
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 | #include <iostream> int main() { int n; std::cin >> n; int *tab = new int[202000]; int j = 0; for(int i = 0; i < n; i++) { std::cin >> j; ++tab[j]; } int max = 0; for(int i = 0; i < 202000; i++) { tab[i+1] += tab[i] / 2; if(tab[i+1]) max = i+1; } std::cout << max << std::endl; delete [] tab; } |