DMOPC '22 Contest 3 P3 - Ina's Takodachis

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

The popular idol Ninomae Ina'nis is hosting a New Year concert! Many of her fans, known as Takodachis, have come out to watch her perform. At the reception, there are N Takodachis waiting in line. Initially, the ith Takodachi has height hi. Seeing her Takodachis with different heights, she starts to wonder if the taller ones will block the shorter Takodachis in the concert. That's when she came up with the brilliant idea of making them all have the same height.

To do so, Ina can perform the following operation: choose two Takodachis indexed at i and j such that i<j. Then, she will increment the ith Takodachi's height by 1 and increment the jth Takodachi's height by 2.

What is the minimum possible height such that all Takodachis' height can be equal to it after some, possibly zero, number of operations?

Constraints

2N2×105

1hi1012

Subtask 1 [40%]

2N100

1hi103

Subtask 2 [60%]

No additional constraints.

Input Specification

The first line contains an integer N, the number of Takodachis.

The next line contains N space-separated integers, with the ith integer hi indicating the height of the ith Takodachi.

Output Specification

If it is impossible to make all Takodachis the same height, output 1.

Otherwise, output the minimum possible height such that all Takodachis can be equal to that height after some, possibly zero, number of operations.

Sample Input

Copy
4
1 2 3 4

Sample Output

Copy
10

Comments

There are no comments at the moment.