#include <cstdio> #include <vector> std::vector<bool> coins(201740, false); int main() { int count; int value; int max_value = 0; scanf("%d", &count); for (int i = 0; i < count; ++i) { scanf("%d", &value); while (coins[value]) { coins[value] = false; ++value; } coins[value] = true; if (value > max_value) { max_value = value; } } printf("%d\n", max_value); }
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 | #include <cstdio> #include <vector> std::vector<bool> coins(201740, false); int main() { int count; int value; int max_value = 0; scanf("%d", &count); for (int i = 0; i < count; ++i) { scanf("%d", &value); while (coins[value]) { coins[value] = false; ++value; } coins[value] = true; if (value > max_value) { max_value = value; } } printf("%d\n", max_value); } |