#include <cmath> #include <iostream> using namespace std; void showArr(int arr[], int arrSize); int main() { ios_base::sync_with_stdio(0); cin.tie(0); long n; cin >> n; const int ArrSize = 300000; int* expo = new int[ArrSize]; for (int i = 0; i < ArrSize; i++) expo[i] = 0; int tmp; int max = 0; for (int i = 0; i < n; i++) { cin >> tmp; expo[tmp]++; if (tmp > max) max = tmp; } int index = 1; while (index <= max) { if (expo[index] > 1) { int pot = 1; while (pow(2, pot) <= expo[index]) pot++; pot--; expo[index+pot]++; if (index+pot > max) max = index+pot; } index++; } cout << max; return 0; } void showArr(int arr[], int arrSize) { for (int i = 0; i < arrSize; i++) cout << arr[i] << " "; cout << endl; }
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 52 53 | #include <cmath> #include <iostream> using namespace std; void showArr(int arr[], int arrSize); int main() { ios_base::sync_with_stdio(0); cin.tie(0); long n; cin >> n; const int ArrSize = 300000; int* expo = new int[ArrSize]; for (int i = 0; i < ArrSize; i++) expo[i] = 0; int tmp; int max = 0; for (int i = 0; i < n; i++) { cin >> tmp; expo[tmp]++; if (tmp > max) max = tmp; } int index = 1; while (index <= max) { if (expo[index] > 1) { int pot = 1; while (pow(2, pot) <= expo[index]) pot++; pot--; expo[index+pot]++; if (index+pot > max) max = index+pot; } index++; } cout << max; return 0; } void showArr(int arr[], int arrSize) { for (int i = 0; i < arrSize; i++) cout << arr[i] << " "; cout << endl; } |