Problem I

Statement
Copy Copied
I. Kevin and Nivektime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output Kevin and Nivek are competing for the title of "The Best Kevin". They aim to determine the winner through $$$n$$$ matches.The $$$i$$$-th match can be one of two types:  Type 1: Kevin needs to spend $$$a_i$$$ time to defeat Nivek and win the match. If Kevin doesn't spend $$$a_i$$$ time on it, Nivek will win the match.  Type 2: The outcome of this match depends on their historical records. If Kevin's number of wins is greater than or equal to Nivek's up to this match, then Kevin wins. Otherwise, Nivek wins. Kevin wants to know the minimum amount of time he needs to spend to ensure he wins at least $$$k$$$ matches.Output the answers for $$$k = 0, 1, \ldots, n$$$.InputEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of matches.The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-1 \leq a_i \leq 10^9$$$).If $$$a_i = -1$$$, the $$$i$$$-th match is of Type 2. Otherwise, the $$$i$$$-th match is of Type 1, and $$$a_i$$$ represents the amount of time Kevin needs to spend to win this match.It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. OutputFor each test case, output $$$n + 1$$$ integers. The $$$i$$$-th integer represents the minimum amount of time to win at least $$$i-1$$$ matches.ExampleInput35-1 -1 -1 -1 -153 2 5 4 15100 -1 -1 -1 1Output0 0 0 0 0 0 
0 1 3 6 10 15 
0 1 100 100 100 101 
NoteIn the first test case, all matches are of Type 2. Kevin can automatically win all matches.In the second test case, all matches are of Type 1. Kevin can choose matches in increasing order of $$$a_i$$$.In the third test case:  If Kevin spends $$$a_1$$$ time on match $$$1$$$, he can win matches $$$1, 2, 3, 4$$$.  If Kevin spends $$$a_5$$$ time on match $$$5$$$, he can win match $$$5$$$.  If Kevin spends $$$a_1$$$ time on match $$$1$$$ and $$$a_5$$$ time on match $$$5$$$, he can win all matches.