#include <iostream> using namespace std; const int MAX_EXP = 201718 + 12; int purse[MAX_EXP]; int main() { int n; cin >> n; int max_nom = 0; for (int i=0; i<n; ++i) { int ai; cin >> ai; ++purse[ai]; if (max_nom < ai) max_nom = ai; } for (int i=0; i < max_nom; ++i) { purse[i+1] += purse[i] / 2; purse[i] %= 2; } while (purse[max_nom] > 1) { ++max_nom; purse[max_nom] = purse[max_nom-1] / 2; purse[max_nom-1] %= 2; } cout << max_nom << endl; 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 33 34 35 36 | #include <iostream> using namespace std; const int MAX_EXP = 201718 + 12; int purse[MAX_EXP]; int main() { int n; cin >> n; int max_nom = 0; for (int i=0; i<n; ++i) { int ai; cin >> ai; ++purse[ai]; if (max_nom < ai) max_nom = ai; } for (int i=0; i < max_nom; ++i) { purse[i+1] += purse[i] / 2; purse[i] %= 2; } while (purse[max_nom] > 1) { ++max_nom; purse[max_nom] = purse[max_nom-1] / 2; purse[max_nom-1] %= 2; } cout << max_nom << endl; return 0; } |