Team Training

면접 대비

시간 제한1초메모리 제한2048 MB

요약
순열에서 서로 겹치지 않는 연속한 세 원소 묶음 n개를 골라 각 묶음의 첫째, 둘째, 셋째를 1,2,3팀에 배정할 때 세 팀 합의 사전식 최대를 구한다.
난이도

보통10점 중 7점

유형
그리디, 동적 계획법, 스택
정답자
아직 제출이 없습니다

문제

Today, Amir had another training session with his coach Timo from Kazakhstan.

Today, Timo had 3n3n students at his training session. Each student, indexed as ii, had their own level denoted as p_ip\_i. It is important to note that all students had different levels.

Usually, Timo divided the students into teams of three participants. However, today he decided to change the system and divide the students into three teams. His approach was as follows: he selected three consecutive students from the list and distributed them among the three teams. The first student was sent 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 the students were distributed.

The level of a team was determined by the sum of the levels of participants in it. Timo wanted to maximize the level of the first team. If there were multiple options for maximizing the level of the first team, he would maximize the level of the second team. If there were still multiple options, he would maximize the level of the third team.

For example, consider the list of students \[3,1,5,4,2,6]\[3, 1, 5, 4, 2, 6]. Suppose Timo would first choose \[1,5,4]\[1, 5, 4], then \[3,2,6]\[3, 2, 6]. As a result, the teams would have the following levels: \[1+3,,5+2,,4+6]=\[4,7,10]\[1{+}3, \\, 5{+}2, \\, 4{+}6] = \[4, 7, 10]. However, if Timo had chosen \[5,4,2]\[5, 4, 2] first, and then \[3,1,6]\[3, 1, 6], the team levels would have been \[8,5,8]\[8, 5, 8], which is a better distribution according to the criteria.

Find the levels of the teams if Timo divides people into teams optimally.

입력

The first line contains a single integer tt (1≤t≤1051 \le t \le 10^5): the number of test cases. For each test case:

The first line contains an integer nn (1≤n≤1051 \le n \le 10^5): the number of students.

The second line contains 3n3n distinct integers p_1,p_2,…,p_3np\_1, p\_2, \ldots, p\_{3n} (1≤p_i≤3n1 \le p\_i \le 3n): the levels of the students.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

출력

Output a line with three integers: the levels of the first, second, and third teams in the optimal division.

예제1

  1. 예제 1

    입력
    2
    1
    2 3 1
    2
    3 1 5 4 2 6
    
    예상 출력
    2 3 1
    8 5 8