#include<cstdio> int n,x,i,m,f[210000]; inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';} int main(){ read(n); while(n--){ read(x); f[x]++; if(x>m)m=x; } for(i=0;i<=m;i++)if(f[i]>1){ if(i==m)m++; f[i+1]+=f[i]>>1; } printf("%d",m); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include<cstdio> int n,x,i,m,f[210000]; inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';} int main(){ read(n); while(n--){ read(x); f[x]++; if(x>m)m=x; } for(i=0;i<=m;i++)if(f[i]>1){ if(i==m)m++; f[i+1]+=f[i]>>1; } printf("%d",m); } |