#C9140. Optimal Robot Team Energy
Optimal Robot Team Energy
Optimal Robot Team Energy
You are given an even number of robots, each with a certain energy level. Your task is to form teams of two robots in such a way that the total team energy is maximized. The energy of a team is defined as the minimum energy level of the two robots in that team. By pairing the robots optimally, the maximum total energy is achieved.
More formally, let the energy levels be \(a_1, a_2, \dots, a_n\). After sorting them in non-decreasing order (i.e., \(a_1 \leq a_2 \leq \cdots \leq a_n\)), the maximum sum of team energies is given by:
\[ \sum_{i=1}^{n/2} a_i \]
It is guaranteed that the number of robots \(n\) is even.
inputFormat
The first line contains an even integer \(n\), which represents the number of robots.
The second line contains \(n\) space-separated integers, each denoting the energy level of a robot.
outputFormat
Output a single integer: the maximum total energy of the teams formed by the optimal pairing.
## sample4
5 3 2 7
5
</p>