#include <iostream> #include <vector> using namespace std; int main(void) { ios_base::sync_with_stdio(false); const int vSize = 202000; std::vector<int> v(vSize, 0); int size, element; std::cin >> size; int count = size; int theBiggest = 0; while (count-- ) { std::cin >> element; v[element]++; } for(int i = 0; i < vSize - 1; i++) { if(v[i]) { v[i + 1] += v[i] / 2; theBiggest = i; } } std::cout << theBiggest << 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 28 29 | #include <iostream> #include <vector> using namespace std; int main(void) { ios_base::sync_with_stdio(false); const int vSize = 202000; std::vector<int> v(vSize, 0); int size, element; std::cin >> size; int count = size; int theBiggest = 0; while (count-- ) { std::cin >> element; v[element]++; } for(int i = 0; i < vSize - 1; i++) { if(v[i]) { v[i + 1] += v[i] / 2; theBiggest = i; } } std::cout << theBiggest << std::endl; return 0; } |