#include<cstdio> int tab[202001]; int main(){ int n; scanf("%d", &n); int pom; for (int i=0; i<n; i++){ scanf("%d", &pom); tab[pom]++; } int last=0; for (int i=0; i<202000; i++){ tab[i+1]+=tab[i]/2; if (tab[i]==1) last=i; } printf("%d", last); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include<cstdio> int tab[202001]; int main(){ int n; scanf("%d", &n); int pom; for (int i=0; i<n; i++){ scanf("%d", &pom); tab[pom]++; } int last=0; for (int i=0; i<202000; i++){ tab[i+1]+=tab[i]/2; if (tab[i]==1) last=i; } printf("%d", last); } |