#K64417. Maximum Operations to Reduce Planet Populations
Maximum Operations to Reduce Planet Populations
Maximum Operations to Reduce Planet Populations
You are given n planets, each with a certain population. In one operation, you may choose any two different planets that both have a population of at least 1, and decrease each of their populations by 1. Your task is to determine the maximum number of operations you can perform.
In mathematical terms, if we denote the total population by \(T\) and the maximum population among the planets by \(M\), then the answer is given by:
[ \text{answer} = \min\Big( \Big\lfloor\frac{T}{2}\Big\rfloor,, T - M \Big)]
This is because in each operation you reduce the total population by 2. However, if one planet has too many inhabitants (i.e. \(M > T - M\)), then that planet would have leftover population that cannot be paired for further reduction.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains a single integer \(n\) which represents the number of planets.
- The second line contains \(n\) space-separated integers, where the \(i^{th}\) integer denotes the population of the \(i^{th}\) planet.
outputFormat
Output a single integer to stdout representing the maximum number of operations that can be performed.
## sample3
3 2 1
3