atcoder#DIVERTA20192C. Successive Subtraction
Successive Subtraction
Score : points
Problem Statement
There are integers, , written on a blackboard.
We will repeat the following operation times so that we have only one integer on the blackboard.
- Choose two integers and on the blackboard and erase these two integers. Then, write a new integer .
Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible value of the final integer on the blackboard, and a sequence of operations that maximizes the final integer, in the format below.
Here and represent the integers and chosen in the -th operation, respectively.
If there are multiple sequences of operations that maximize the final integer, any of them will be accepted.
3
1 -1 2
4
-1 1
2 -2
If we choose and in the first operation, the set of integers written on the blackboard becomes .
Then, if we choose and in the second operation, the set of integers written on the blackboard becomes .
In this case, we have as the final integer. We cannot end with a greater integer, so the answer is .
3
1 1 1
1
1 1
1 0