#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e6;
int a[MAX];
int main(){
ios_base::sync_with_stdio(0);
int n, x, odp = 0;
cin >> n;
for(int i = 0; i < n; i++){
cin >> x;
a[x]++;
}
for(int i = 1; i < MAX; i++){
a[i] += (a[i-1]>>1);
a[i-1] %= 2;
if(a[i] != 0) odp = max(odp, i);
}
cout << odp;
}
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 | #include <bits/stdc++.h> using namespace std; const int MAX = 2e6; int a[MAX]; int main(){ ios_base::sync_with_stdio(0); int n, x, odp = 0; cin >> n; for(int i = 0; i < n; i++){ cin >> x; a[x]++; } for(int i = 1; i < MAX; i++){ a[i] += (a[i-1]>>1); a[i-1] %= 2; if(a[i] != 0) odp = max(odp, i); } cout << odp; } |
English