#include <iostream> #include <cstdlib> using namespace std; long int n, i,a, maks; long int ilepoteg2[1000000]; int main(void) { ios_base::sync_with_stdio(0); cin>>n; //n - 10^6 przypadkow maks=0; for (i=1;i<=n;i++) { cin>>a; ilepoteg2[a]++; if (ilepoteg2[a]>1) { ilepoteg2[a+1]+=ilepoteg2[a]/2; ilepoteg2[a]=ilepoteg2[a]%2; a++; } if (maks<a) maks=a; } if (ilepoteg2[maks]>1) maks++; cout<<maks; 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 | #include <iostream> #include <cstdlib> using namespace std; long int n, i,a, maks; long int ilepoteg2[1000000]; int main(void) { ios_base::sync_with_stdio(0); cin>>n; //n - 10^6 przypadkow maks=0; for (i=1;i<=n;i++) { cin>>a; ilepoteg2[a]++; if (ilepoteg2[a]>1) { ilepoteg2[a+1]+=ilepoteg2[a]/2; ilepoteg2[a]=ilepoteg2[a]%2; a++; } if (maks<a) maks=a; } if (ilepoteg2[maks]>1) maks++; cout<<maks; return 0; } |