#include <stdio.h> int m[201738]; int main() { int n,i,h,t; h=0; scanf("%d", &n); for (i=0; i<n; ++i) { scanf("%d", &t); m[t]++; } for (i=0; i<201738; ++i) { if (m[i]>0) h=i; // printf("A %d %d %d %d\n", i, m[i], m[i+1], h); m[i+1]+=m[i]/2; m[i]=m[i]%2; // printf("B %d %d %d %d\n", i, m[i], m[i+1], h); } printf("%d", h); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <stdio.h> int m[201738]; int main() { int n,i,h,t; h=0; scanf("%d", &n); for (i=0; i<n; ++i) { scanf("%d", &t); m[t]++; } for (i=0; i<201738; ++i) { if (m[i]>0) h=i; // printf("A %d %d %d %d\n", i, m[i], m[i+1], h); m[i+1]+=m[i]/2; m[i]=m[i]%2; // printf("B %d %d %d %d\n", i, m[i], m[i+1], h); } printf("%d", h); } |