LCC '24 Contest 2 S2 - Min-Maxing

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 3.5s
Memory limit: 256M

Author:
Problem types

As you enter the next unfamiliar room, a voice begins to echo:

Welcome to your second game.

Here are the rules of the game:

  1. You are given N numbers and you need to form groups of M. It is guaranteed that N is divisible by M.

  2. The sum of the group is equal to the sum of all the numbers in the group, not including the smallest number

  3. 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 N and M.

The next line will contain N integers, x_{i}, separated by spaces.

Output Specification

Output 2 lines, the maximum overall sum and the minimum overall sum after splitting the N integers into groups of M numbers.

Constraints

It is guaranteed that N is divisible by M

Subtask 1 [20%]:

1 \le x_{i} \le 10^2

1 \le M \le 2

1 \le N \le 10

Subtask 2 [80%]:

1 \le x_{i} \le 10^6

1 \le M \le 10^6

1 \le N \le 10^6

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 21, 12, 16, 13, making the overall sum equal to 62.


Comments

There are no comments at the moment.