MNYC '17: 2048

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 64M

Problem types

Gabriel is playing 2048. In this game, squares appear with a number on it. All the numbers are positive powers of 2. You can combine two of the same power to get one power greater. For example, if you combine two 32s you get a 64 square. Gabriel has N squares and wants to know the biggest square he can obtain from combining.

Input Specification

A single integer, N (1 \le N \le 1000), the number of squares.

The second line contains N integers, x_i, the number on the squares. x_i = 2^p, p \in [1, 20]

Output Specification

A single integer, the biggest square can Gabriel can theoretically create.

Sample Input 1

2 4 2

Sample Output 1


Explanation for Sample Output 1

Gabriel can combine the two 2s to make a 4 and then he can combine the two 4s he has to make an 8.

Sample Input 2

2 2 8 16 32

Sample Output 2


Explanation for Sample Output 2

Although Gabriel can combine the two 2s, he cannot make any more moves. The biggest square he has is 32.