#include <map> #include <vector> static const int LOG_ONE_MILION = 20; static const int MAX = 201718; int main() { int count; int number; scanf("%d", &count); std::vector<int> v(MAX + LOG_ONE_MILION + 2); for (auto i = 0; i < count; i++) { scanf("%d", &number); v[number]++; } int best = 0; for (auto i = 0; i < MAX + LOG_ONE_MILION + 1; i++) { v[i + 1] += v[i] / 2; if (v[i] > 0) { best = i; } } printf("%d\n", best); 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 | #include <map> #include <vector> static const int LOG_ONE_MILION = 20; static const int MAX = 201718; int main() { int count; int number; scanf("%d", &count); std::vector<int> v(MAX + LOG_ONE_MILION + 2); for (auto i = 0; i < count; i++) { scanf("%d", &number); v[number]++; } int best = 0; for (auto i = 0; i < MAX + LOG_ONE_MILION + 1; i++) { v[i + 1] += v[i] / 2; if (v[i] > 0) { best = i; } } printf("%d\n", best); return 0; } |