Three Investigators

시간 제한5초메모리 제한512 MB

요약
각 접두사 길이 k마다 그 접두사에서 최대 5개의 비감소 부분수열로 제거할 수 있는 값의 합의 최댓값을 구한다.
난이도

어려움10점 중 8점

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

문제

Chitanda owns a sequence a1, a2, . . . , an with n integers, and she wants to play a game with Skywalkert.

First, Chitanda will select a parameter k and remove ak+1, ak+2, . . . , an. Thus there will be exactly k integers in sequence a.

Then Skywalkert can select a subsequence of a and remove it from a. Assume the selected subsequence is ap1, ap2, . . . , apm. He should ensure that p1 < p2 < . . . < pm and ap1 ≤ ap2 ≤ . . . ≤ apm.

Skywalkert can do the above operation for no more than 5 times. His score is the sum of all the integers selected by him in these no more than 5 operations.

For each possible parameter k selected by Chitanda, write a program to help Skywalkert know the maximum score he can achieve.

입력

The first line of the input contains an integer T (1 ≤ T ≤ 10 000), denoting the number of test cases.

In each test case, there is one integer n (1 ≤ n ≤ 100 000) on the first line, denoting the length of a.

In the second line of a test case, there are n integers a1, a2, . . . , an (1 ≤ ai ≤ 109), denoting the sequence.

It is guaranteed that the sum of n in all test cases is at most 500 000.

출력

For each test case, print a single line containing n integers s1, s2, . . . , sn, where si denotes the maximum score of Skywalkert when k = i.

예제1

  1. 예제 1

    입력
    1
    8
    8 7 6 5 1 3 2 4
    
    예상 출력
    8 15 21 26 27 30 30 34