#include <iostream>
#include <bitset>
const std::size_t MAX_COIN_SIZE = 250000;
int main() {
std::size_t n;
std::cin >> n;
std::bitset<MAX_COIN_SIZE> has_coin;
std::size_t max = 0;
for (std::size_t i = 0; i < n; ++i) {
std::size_t a_i;
std::cin >> a_i;
while (has_coin[a_i]) {
has_coin.reset(a_i);
++a_i;
}
has_coin.set(a_i);
max = std::max(max, a_i);
}
std::cout << max << '\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 | #include <iostream> #include <bitset> const std::size_t MAX_COIN_SIZE = 250000; int main() { std::size_t n; std::cin >> n; std::bitset<MAX_COIN_SIZE> has_coin; std::size_t max = 0; for (std::size_t i = 0; i < n; ++i) { std::size_t a_i; std::cin >> a_i; while (has_coin[a_i]) { has_coin.reset(a_i); ++a_i; } has_coin.set(a_i); max = std::max(max, a_i); } std::cout << max << '\n'; } |
English