#include<bits/stdc++.h>
using namespace std;
int tab[1000000];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int a,b;
cin>>a;
for(int x=0;x<a;x++)
{
cin>>b;
tab[b]++;
}
int pom=tab[0]/2;
int maks=0;
for(int x=1;x<1000000;x++)
{
tab[x]+=pom;
if(tab[x]!=0)
maks=x;
pom=tab[x]/2;
}
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 | #include<bits/stdc++.h> using namespace std; int tab[1000000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a,b; cin>>a; for(int x=0;x<a;x++) { cin>>b; tab[b]++; } int pom=tab[0]/2; int maks=0; for(int x=1;x<1000000;x++) { tab[x]+=pom; if(tab[x]!=0) maks=x; pom=tab[x]/2; } cout<<maks; return 0; } |
English