#K84017. Highest Team Score
Highest Team Score
Highest Team Score
In a coding contest, each problem is assigned a certain difficulty level represented by an integer. A team is formed by selecting three problems from the available set. The team's score is the sum of the difficulty levels of the selected problems. Your task is to compute the highest possible team score. Formally, given an integer ( n ) and a list of ( n ) integers ( d_1, d_2, \dots, d_n ), if ( n \geq 3 ) then the answer is given by: [ S = d_{(1)} + d_{(2)} + d_{(3)} ] where ( d_{(1)} \geq d_{(2)} \geq d_{(3)} ) are the three largest difficulties. If ( n < 3 ), output -1 as it is not possible to form a team.
Note: The input difficulties may include negative numbers.
inputFormat
The first line contains a single integer ( n ), representing the number of available problems. The second line contains ( n ) space-separated integers ( d_1, d_2, \dots, d_n ) which denote the difficulty levels of the problems.
outputFormat
Output a single integer which is the highest possible team score by summing the three largest difficulties if at least three problems are available, or output -1 if a team cannot be formed.## sample
6
-1 3 2 4 0 -5
9