#include<cstdio> #include<algorithm> using namespace std; int t[213013]; int main() { int n,a; scanf ("%d", &n); for (int i=0; i<n; i++) { scanf ("%d", &a); t[a]++; } int licz=t[0]; int msc=0; bool r=true; while (licz<n||t[msc]!=0) { r=true; licz+=t[msc+1]; t[msc+1]+=t[msc]/2; if (t[msc]%2==1) r=false; msc++; } if (r) printf ("%d", msc); else printf ("%d", msc-1); 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 | #include<cstdio> #include<algorithm> using namespace std; int t[213013]; int main() { int n,a; scanf ("%d", &n); for (int i=0; i<n; i++) { scanf ("%d", &a); t[a]++; } int licz=t[0]; int msc=0; bool r=true; while (licz<n||t[msc]!=0) { r=true; licz+=t[msc+1]; t[msc+1]+=t[msc]/2; if (t[msc]%2==1) r=false; msc++; } if (r) printf ("%d", msc); else printf ("%d", msc-1); return 0; } |