#include<iostream> using namespace std; int main() { int n, a, max=-1, odp=0; int *monet = new int[201720](); cin >> n; for (int i = 0; i < n; i++) { cin >> a; monet[a]++; if (a > max) max = a; } for (int i = 0; i <= max; i++) { if (monet[i] > 0) odp = i; monet[i + 1] += monet[i] / 2; } if (monet[max + 1] > 0) while (monet[max + 1] >= 1) { monet[max + 1] /= 2; odp++; } cout << odp; 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 | #include<iostream> using namespace std; int main() { int n, a, max=-1, odp=0; int *monet = new int[201720](); cin >> n; for (int i = 0; i < n; i++) { cin >> a; monet[a]++; if (a > max) max = a; } for (int i = 0; i <= max; i++) { if (monet[i] > 0) odp = i; monet[i + 1] += monet[i] / 2; } if (monet[max + 1] > 0) while (monet[max + 1] >= 1) { monet[max + 1] /= 2; odp++; } cout << odp; return 0; } |