#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
bool tab[10000005];
int x, maks;
void dod(int x){
if (tab[x]==false){
tab[x]=true;
maks=max(x,maks);
return;
}
if(tab[x]==true){
tab[x]=false;
dod(x+1);
}
}
int main(){
int n;
scanf("%d", &n);
for(int i=0; i<n; i++){
scanf("%d", &x);
dod(x);
}
printf("%d", maks);
}
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 <cstdio> #include <cmath> #include <algorithm> using namespace std; bool tab[10000005]; int x, maks; void dod(int x){ if (tab[x]==false){ tab[x]=true; maks=max(x,maks); return; } if(tab[x]==true){ tab[x]=false; dod(x+1); } } int main(){ int n; scanf("%d", &n); for(int i=0; i<n; i++){ scanf("%d", &x); dod(x); } printf("%d", maks); } |
English