#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int potega[202000];
for (int i = 0; i < 202000; ++i)
potega[i] = 0;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
++potega[a];
}
int akt_pot = 0;
int odp = 0;
while (potega[akt_pot] > 0 || akt_pot <= 201718) {
if (potega[akt_pot] > 0)
odp = akt_pot;
int dodaj_do_wyzszej = potega[akt_pot] / 2;
// if (dodaj_do_wyzszej > 0) {
// cout << "Było " << potega[akt_pot] << " potęg 2^" << \
// akt_pot << ", dodaję " << dodaj_do_wyzszej << " do wyższej..." << endl;
// }
potega[akt_pot + 1] += dodaj_do_wyzszej;
++akt_pot;
}
cout << odp << 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 | #include <iostream> using namespace std; int main() { int n; cin >> n; int potega[202000]; for (int i = 0; i < 202000; ++i) potega[i] = 0; for (int i = 0; i < n; ++i) { int a; cin >> a; ++potega[a]; } int akt_pot = 0; int odp = 0; while (potega[akt_pot] > 0 || akt_pot <= 201718) { if (potega[akt_pot] > 0) odp = akt_pot; int dodaj_do_wyzszej = potega[akt_pot] / 2; // if (dodaj_do_wyzszej > 0) { // cout << "Było " << potega[akt_pot] << " potęg 2^" << \ // akt_pot << ", dodaję " << dodaj_do_wyzszej << " do wyższej..." << endl; // } potega[akt_pot + 1] += dodaj_do_wyzszej; ++akt_pot; } cout << odp << endl; return 0; } |
English