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
#include <iostream>

using namespace std;

#define MAX_COIN_VALUE 201718

int main()
{
    	int n;
		cin >> n;
		int coins[MAX_COIN_VALUE + 1 + 30];
		for (int i = 0; i <= MAX_COIN_VALUE + 30; i++) {
			coins[i] = 0;
		}
		for (int i = 0; i < n; i++) {
			int coin;
			cin >> coin;
			coins[coin]++;
		}
		int biggestCoin = 0;
		for (int i = 0; i <= MAX_COIN_VALUE + 30; i++) {
			if (coins[i] != 0) {
				biggestCoin = i;
			}
			if (i + 1 <= MAX_COIN_VALUE + 30) {
				coins[i + 1] += coins[i] / 2;
			}
		}
		cout << biggestCoin;

    return 0;
}