#include <bits/stdc++.h>
//#define int long long
#define st first
#define nd second
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define mt make_tuple
#define e(a, b) get<b>(a)
using namespace std;
int tbl[2000000];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
int a;
for (int i=0; i<n; i++)
{
cin>>a;
tbl[a]++;
}
a=0;
for (int i=0; i<2000000; i++)
{
if (tbl[i]!=0)
a=i;
tbl[i+1]+=tbl[i]/2;
tbl[i]%=2;
}
cout<<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 | #include <bits/stdc++.h> //#define int long long #define st first #define nd second #define mp(a, b) make_pair(a, b) #define pb push_back #define mt make_tuple #define e(a, b) get<b>(a) using namespace std; int tbl[2000000]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; int a; for (int i=0; i<n; i++) { cin>>a; tbl[a]++; } a=0; for (int i=0; i<2000000; i++) { if (tbl[i]!=0) a=i; tbl[i+1]+=tbl[i]/2; tbl[i]%=2; } cout<<a; return 0; } |
English