#include <cstdio> int n, g, x, out; int t [300001]; int main () { scanf ("%d",&n); for (g=0; g!=n; g++) { scanf ("%d",&x); t[x]++; } for (g=0; g!=300000; g++) { if (t[g]!=0) out=g; t[g+1]+=(t[g]/2); } printf ("%d\n",out); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <cstdio> int n, g, x, out; int t [300001]; int main () { scanf ("%d",&n); for (g=0; g!=n; g++) { scanf ("%d",&x); t[x]++; } for (g=0; g!=300000; g++) { if (t[g]!=0) out=g; t[g+1]+=(t[g]/2); } printf ("%d\n",out); return 0; } |