#include <cstdio> using namespace std; const int MAX_NOM = 201740; int monety[MAX_NOM]; int max_nom; int main() { int n, a_i; scanf("%d", &n); while (n--) { scanf("%d", &a_i); ++monety[a_i]; if (max_nom < a_i) max_nom = a_i; } for (int i = 0; i < max_nom; ++i) if (1 < monety[i]) { monety[i + 1] += monety[i] / 2; monety[i] %= 2; } while (1 < monety[max_nom]) { monety[max_nom + 1] += monety[max_nom] / 2; monety[max_nom] %= 2; ++max_nom; } printf("%d\n", max_nom); 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 | #include <cstdio> using namespace std; const int MAX_NOM = 201740; int monety[MAX_NOM]; int max_nom; int main() { int n, a_i; scanf("%d", &n); while (n--) { scanf("%d", &a_i); ++monety[a_i]; if (max_nom < a_i) max_nom = a_i; } for (int i = 0; i < max_nom; ++i) if (1 < monety[i]) { monety[i + 1] += monety[i] / 2; monety[i] %= 2; } while (1 < monety[max_nom]) { monety[max_nom + 1] += monety[max_nom] / 2; monety[max_nom] %= 2; ++max_nom; } printf("%d\n", max_nom); return 0; } |