// Michał Seweryn #include "bits/stdc++.h" using Int = long long; int main() { std::ios_base::sync_with_stdio(false); Int n; std::cin >> n; std::vector<Int> a(n); for (Int i = 0; i < n; ++i) { std::cin >> a[i]; } std::vector<Int> b(*std::max_element(a.begin(), a.end()) + 1, 0); for (Int x : a) { ++b[x]; } for (Int i = 0; i < (Int) b.size(); ++i) { if (b[i] > 1) { if (i + 1 == (Int) b.size()) { b.push_back(0); } b[i + 1] += b[i] / 2; } } std::cout << b.size() - 1 << '\n'; }
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 | // Michał Seweryn #include "bits/stdc++.h" using Int = long long; int main() { std::ios_base::sync_with_stdio(false); Int n; std::cin >> n; std::vector<Int> a(n); for (Int i = 0; i < n; ++i) { std::cin >> a[i]; } std::vector<Int> b(*std::max_element(a.begin(), a.end()) + 1, 0); for (Int x : a) { ++b[x]; } for (Int i = 0; i < (Int) b.size(); ++i) { if (b[i] > 1) { if (i + 1 == (Int) b.size()) { b.push_back(0); } b[i + 1] += b[i] / 2; } } std::cout << b.size() - 1 << '\n'; } |