#include <iostream>
using namespace std;
const int MAX = 201718;
const int OFFSET = 24;
int main(){
ios_base::sync_with_stdio();
int n;
cin >> n;
int a[n];
for(int i = 0; i < n; i++)
cin >> a[i];
int count[MAX + OFFSET];
for (int i = 0; i < MAX + OFFSET; i++)
count[i] = 0;
for (int i = 0; i < n; i++)
count[a[i]]++;
for (int i = 0; i < MAX + OFFSET - 1; i++)
count[i + 1] += count[i] / 2;
for (int i = MAX + OFFSET - 1; i >= 0; i--)
if (count[i] > 0){
cout << i << endl;
break;
}
/*
for (int i = 0; i < 50; i++)
cout << i << " " << count[i] << 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 = 201718; const int OFFSET = 24; int main(){ ios_base::sync_with_stdio(); int n; cin >> n; int a[n]; for(int i = 0; i < n; i++) cin >> a[i]; int count[MAX + OFFSET]; for (int i = 0; i < MAX + OFFSET; i++) count[i] = 0; for (int i = 0; i < n; i++) count[a[i]]++; for (int i = 0; i < MAX + OFFSET - 1; i++) count[i + 1] += count[i] / 2; for (int i = MAX + OFFSET - 1; i >= 0; i--) if (count[i] > 0){ cout << i << endl; break; } /* for (int i = 0; i < 50; i++) cout << i << " " << count[i] << endl; */ return 0; } |
English