#include <iostream> #include <array> class SKA { protected: std::array<int, 201740> nominaly; int n; public: SKA() { nominaly.fill(0); n = 0; } void readInput() { std::cin >> n; int tmp=0; for(int a=0; a<n; a++) { std::cin >> tmp; nominaly[tmp]++; } } void combine() { int num = 0, quot = 0, lastmax = 0; for(int a=0; a<nominaly.size(); a++) { num = nominaly[a]; if (num != 0) { quot = num>>1; nominaly[a+1] += quot; lastmax = a; } } std::cout << lastmax << std::endl; } void run() { readInput(); combine(); } }; int main(int argc, char** argv) { std::ios_base::sync_with_stdio(false); SKA ska; ska.run(); 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <iostream> #include <array> class SKA { protected: std::array<int, 201740> nominaly; int n; public: SKA() { nominaly.fill(0); n = 0; } void readInput() { std::cin >> n; int tmp=0; for(int a=0; a<n; a++) { std::cin >> tmp; nominaly[tmp]++; } } void combine() { int num = 0, quot = 0, lastmax = 0; for(int a=0; a<nominaly.size(); a++) { num = nominaly[a]; if (num != 0) { quot = num>>1; nominaly[a+1] += quot; lastmax = a; } } std::cout << lastmax << std::endl; } void run() { readInput(); combine(); } }; int main(int argc, char** argv) { std::ios_base::sync_with_stdio(false); SKA ska; ska.run(); return 0; } |