#include <bits/stdc++.h> using namespace std; int a, b, c, n, d, tab[1000001], w; int main () { cin >> n; for (int i = 0; i < n; i++) { cin >> a; tab[a]++; } for (int i = 0; i < 1000000; i++) { d = tab[i]/2; tab[i+1] += d; if (tab[i] != 0) w = i; } cout << w << endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include <bits/stdc++.h> using namespace std; int a, b, c, n, d, tab[1000001], w; int main () { cin >> n; for (int i = 0; i < n; i++) { cin >> a; tab[a]++; } for (int i = 0; i < 1000000; i++) { d = tab[i]/2; tab[i+1] += d; if (tab[i] != 0) w = i; } cout << w << endl; } |