#include <bits/stdc++.h> #define M 1000010 #define pb push_back #define mp make_pair #define st first #define nd second using namespace std; int t[M],n,x,mx,ans; int main(){ scanf("%d",&n); for(int i=1; i<=n; i++){ scanf("%d",&x); t[x]++; mx=max(mx,x); } for(int i=0; i<=mx||t[i]; i++){ t[i+1]+=t[i]>>1; ans=i; } printf("%d",ans); 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 | #include <bits/stdc++.h> #define M 1000010 #define pb push_back #define mp make_pair #define st first #define nd second using namespace std; int t[M],n,x,mx,ans; int main(){ scanf("%d",&n); for(int i=1; i<=n; i++){ scanf("%d",&x); t[x]++; mx=max(mx,x); } for(int i=0; i<=mx||t[i]; i++){ t[i+1]+=t[i]>>1; ans=i; } printf("%d",ans); return 0; } |