As you enter the next unfamiliar room, a voice begins to echo:
Welcome to your second game.
Here are the rules of the game:
You are given numbers and you need to form groups of . It is guaranteed that is divisible by .
The sum of the group is equal to the sum of all the numbers in the group, not including the smallest number
The overall sum can be found by adding all the sums of the groups
Your job is to find the maximum and minimum overall sum. Failure to do so will result in death.
Input Specification
The first line will contain the integer and .
The next line will contain integers, , separated by spaces.
Output Specification
Output lines, the maximum overall sum and the minimum overall sum after splitting the integers into groups of numbers.
Constraints
It is guaranteed that is divisible by
Subtask 1 [20%]:
Subtask 2 [80%]:
Sample Input 1
12 3
9 5 8 8 2 2 4 1 7 10 11 3
Sample Output 1
62
50
Sample Explanation 1
For the maximum possible overall sum, we can form the following groups:
(11, 1, 10), (2, 4, 8), (9, 7, 3), (2, 5, 8)
The sum of each group is , making the overall sum equal to .
Comments