#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
typedef long long ll;
int t[222333];
int main()
{
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for(int i=0; i<n; i++) {
int x;
cin >> x;
t[x]++;
}
int best=0;
for(int i=1; i<222333; i++) {
t[i] += t[i-1]/2;
if(t[i] != 0) {
best = i;
}
}
cout << best;
}
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 | #include<iostream> #include<algorithm> #include<vector> #include<math.h> using namespace std; typedef long long ll; int t[222333]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for(int i=0; i<n; i++) { int x; cin >> x; t[x]++; } int best=0; for(int i=1; i<222333; i++) { t[i] += t[i-1]/2; if(t[i] != 0) { best = i; } } cout << best; } |
English