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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <cstdio>
#include <memory.h>

long* tabCoins;
long nSize = 201718/24 + 2;
long maxRow, nRow, nPos = 0L;
#define DIVI 0x00FFFFFFL
#define DIVI2 0x01000000L
#define DIVINE 24L

void insertCoin(long nextCoin)
{
   nRow = nextCoin / DIVINE;
   tabCoins[nRow] += 1L << (nextCoin % DIVINE);
   while(tabCoins[nRow] & DIVI2)
   {
      tabCoins[nRow] &= DIVI;
      ++nRow;
      tabCoins[nRow] += 1L;
   }
   if(nRow > maxRow)
      maxRow = nRow;
}

long checkMaxPos()
{
   long maxPos = 0L;
   long mask = 1L;
   for(long pos = 0L; pos < DIVINE; ++pos, mask <<= 1)
   {
      if(tabCoins[maxRow] & mask)
         maxPos = pos;
   }
   return maxRow * DIVINE + maxPos;
}

int main() {

   long nCoins = 0L;
   long nValue = 0L;

   scanf("%ld\n", &nCoins);

   tabCoins = new long[nSize];
   memset(tabCoins, 0L, nSize * sizeof(long));

   while(nCoins--)
   {
      scanf("%ld", &nValue);
      insertCoin(nValue);
   }

   long res = checkMaxPos();
   printf("%ld\n", res);

   return 0;
}