Team Training
Time limit1sMemory limit2048 MB
Given 3n distinct levels, repeatedly remove three consecutive students into teams 1, 2, 3, maximizing the team sums lexicographically; output the three sums.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Array, Greedy
- Solved
- No attempts yet
Problem
Today, Amir had another training session with his coach Timo from Kazakhstan.
Today, Timo had students at his training session. Each student, indexed as , had their own level denoted as . All students had different levels.
Usually, Timo divided the students into teams of three participants. Today, however, he decided to change the system and divide the students into three teams. He selected three consecutive students from the list and sent the first one to the first team, the second one to the second team, and the third one to the third team. Then he crossed out these three students from the list and repeated the process until all students were distributed.
The level of a team is the sum of the levels of its participants. Timo wanted to maximize the level of the first team. If several options maximized it, he maximized the level of the second team. If several options still remained, he maximized the level of the third team.
For example, take the list . If Timo first chose and then , the team levels would be . If he chose first and then , the team levels would be , which is the better distribution by the criteria.
Find the levels of the teams when Timo divides the students optimally.
Input
The first line contains a single integer (), the number of test cases. Each test case is given as follows.
The first line contains an integer (), the number of students.
The second line contains distinct integers (), the levels of the students.
The sum of over all test cases does not exceed .
Output
Output a line with three integers: the levels of the first, second, and third teams in the optimal division.