// ConsoleApplication1.cpp : Defines the entry point for the console application. // #include <iostream> long long tab[201719]; using namespace std; int main() { ios_base::sync_with_stdio(0); int N, a; cin >> N; int maks = 0; for (int i = 0; i < N; i++) { cin >> a; if (maks < a) { maks = a; } tab[a]++; } //cout << "MAKS" << maks << endl; //cout << endl; int poz = maks; for (int i = 0; i < maks+1; i++) { tab[i] +=( tab[i - 1] / 2 ); } // teraz jestem na miejscu z najwyzsza potega dwojki long long wyn = tab[poz]; long long dod = 0; while (wyn > 1) { dod++; wyn = wyn / 2; } cout << poz + dod; //cin >> a; 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 37 | // ConsoleApplication1.cpp : Defines the entry point for the console application. // #include <iostream> long long tab[201719]; using namespace std; int main() { ios_base::sync_with_stdio(0); int N, a; cin >> N; int maks = 0; for (int i = 0; i < N; i++) { cin >> a; if (maks < a) { maks = a; } tab[a]++; } //cout << "MAKS" << maks << endl; //cout << endl; int poz = maks; for (int i = 0; i < maks+1; i++) { tab[i] +=( tab[i - 1] / 2 ); } // teraz jestem na miejscu z najwyzsza potega dwojki long long wyn = tab[poz]; long long dod = 0; while (wyn > 1) { dod++; wyn = wyn / 2; } cout << poz + dod; //cin >> a; return 0; } |