#include <bits/stdc++.h>
using namespace std;
const int manx = 1000000;
int m, n, x, a, b, sp, res;
int t[manx];
void add(int a)
{
t[a]++;
res = max(res, a);
if(t[a] == 2)
{
t[a] = 0;
add(a+1);
}
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> x;
t[x]++;
}
for(int i = 1; i <= 201718; i++)
{
if(t[i] != 0) res = max(res, i);
t[i+1] += t[i]/2;
}
cout << res;
}
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 | #include <bits/stdc++.h> using namespace std; const int manx = 1000000; int m, n, x, a, b, sp, res; int t[manx]; void add(int a) { t[a]++; res = max(res, a); if(t[a] == 2) { t[a] = 0; add(a+1); } return; } int main() { ios_base::sync_with_stdio(false); cin >> n; for(int i = 1; i <= n; i ++) { cin >> x; t[x]++; } for(int i = 1; i <= 201718; i++) { if(t[i] != 0) res = max(res, i); t[i+1] += t[i]/2; } cout << res; } |
English