#include<cstdio>
const int MAX=202000;
int main(){
int t[MAX];
for(int i=0;i<MAX;++i){
t[i]=0;
}
int n, x;
scanf("%d", &n);
for(int i=0; i<n; ++i){
scanf("%d", &x);
t[x]+=1;
}
for(int i=1;i<(MAX-2);++i){
t[i]+=t[i-1]/2;
}
int k = 0;
for(int i=0;i<MAX;++i){
if(t[i]==1) k=i;
}
printf("%d\n", k);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include<cstdio> const int MAX=202000; int main(){ int t[MAX]; for(int i=0;i<MAX;++i){ t[i]=0; } int n, x; scanf("%d", &n); for(int i=0; i<n; ++i){ scanf("%d", &x); t[x]+=1; } for(int i=1;i<(MAX-2);++i){ t[i]+=t[i-1]/2; } int k = 0; for(int i=0;i<MAX;++i){ if(t[i]==1) k=i; } printf("%d\n", k); } |
English