Logo
(追記) (追記ここまで)

18594번 - Three Investigators 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB129772641.935%

문제

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
8
8 7 6 5 1 3 2 4

예제 출력 1

8 15 21 26 27 30 30 34

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2019 > Day 1: Songyang Chen Contest 2 I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /