#include <bits/stdc++.h> using namespace std; void initialize() { ios_base::sync_with_stdio(false); cin.tie(0); } template <typename T> T read() { T x; cin >> x; return x; } template <typename T> vector <T> read_n(unsigned n) { vector <T> x(n); generate(x.begin(), x.end(), read <T>); return x; } int main() { initialize(); auto coins = vector <int>(201740); auto n = read <int>(); while (n--) coins[read <int>()]++; auto result = 0; for (auto i = 1; i < int(coins.size()); i++) { coins[i] += (coins[i - 1] >> 1); if (coins[i]) result = i; } cout << result << '\n'; 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <bits/stdc++.h> using namespace std; void initialize() { ios_base::sync_with_stdio(false); cin.tie(0); } template <typename T> T read() { T x; cin >> x; return x; } template <typename T> vector <T> read_n(unsigned n) { vector <T> x(n); generate(x.begin(), x.end(), read <T>); return x; } int main() { initialize(); auto coins = vector <int>(201740); auto n = read <int>(); while (n--) coins[read <int>()]++; auto result = 0; for (auto i = 1; i < int(coins.size()); i++) { coins[i] += (coins[i - 1] >> 1); if (coins[i]) result = i; } cout << result << '\n'; return 0; } |