#include <iostream>
#include <array>
class {
void get() {
int n, x;
std::cin >> n;
for(int i = 0; i < n; ++i) {
std::cin >> x;
coins[x]++;
}
}
void process() {
auto it = coins.begin();
for(;it < coins.end() - 2; ++it) {
if(*it == 0) {
continue;
}
if(*it == 1) {
max = it - coins.begin();
}
else {
*(it + 1) += *it / 2;
}
}
++it;
if(*it >= 1) {
int a_dist = it - coins.begin();
while(*it > 1) {
++a_dist;
*it /= 2;
}
max = a_dist;
}
}
void display() {
std::cout << max;
}
std::array<int, 201719> coins = {{}};
int max;
public:
int run()
{
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
get();
process();
display();
return 0;
}
} moneybox;
int main() { return moneybox.run(); }
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <iostream> #include <array> class { void get() { int n, x; std::cin >> n; for(int i = 0; i < n; ++i) { std::cin >> x; coins[x]++; } } void process() { auto it = coins.begin(); for(;it < coins.end() - 2; ++it) { if(*it == 0) { continue; } if(*it == 1) { max = it - coins.begin(); } else { *(it + 1) += *it / 2; } } ++it; if(*it >= 1) { int a_dist = it - coins.begin(); while(*it > 1) { ++a_dist; *it /= 2; } max = a_dist; } } void display() { std::cout << max; } std::array<int, 201719> coins = {{}}; int max; public: int run() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); get(); process(); display(); return 0; } } moneybox; int main() { return moneybox.run(); } |
English