Advertisement
Guest User

C

a guest
May 19th, 2013
2,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. const int NMAX = 100005;
  4. int a[NMAX], n, tmax, tcnt;
  5.  
  6. int main() {
  7.     scanf("%d", &n);
  8.     for(int i = 0; i < n; i++) scanf("%d", &a[n - i - 1]);
  9.     while (n > 0) {
  10.         int j = n - 1, cnt;
  11.         while (j > 0 && a[n - 1] == a[j - 1]) --j;
  12.         cnt = n - j;
  13.         if (cnt % 2 == 1) {
  14.             tcnt++, n--;
  15.             if (a[n] > tmax) tmax = a[n];
  16.         }
  17.         cnt /= 2;
  18.         n -= cnt;
  19.         for(int i = 0; i < cnt; i++) a[n - 1 - i]++;
  20.     }
  21.     printf("%d\n", tmax - tcnt + 1);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement