#include <iostream> int M[300000]; int main() { int max = -1; int n; std::cin >> n; for (int i=0;i<n;++i) { int m; std::cin >> m; while (M[m] > 0) { M[m] -= 1; ++m; } M[m]++; max = std::max(max, m); } std::cout << max; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> int M[300000]; int main() { int max = -1; int n; std::cin >> n; for (int i=0;i<n;++i) { int m; std::cin >> m; while (M[m] > 0) { M[m] -= 1; ++m; } M[m]++; max = std::max(max, m); } std::cout << max; } |