IAEPC Preliminary Contest (Codeforces Round 999, Div. 1 + Div. 2)
I
Kevin and Nivek
Codeforces
3500
原题
← H2→
翻译中…

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$.

翻译中…

Input

翻译中…

Each 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$.

翻译中…

Output

翻译中…

For each test case, output $n + 1$ integers. The $i$-th integer represents the minimum amount of time to win at least $i-1$ matches.

翻译中…

Note

翻译中…

In 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.
翻译中…

样例

Input #1
3
5
-1 -1 -1 -1 -1
5
3 2 5 4 1
5
100 -1 -1 -1 1
Output #1
0 0 0 0 0 0
0 1 3 6 10 15
0 1 100 100 100 101
InputCopy OutputCopy
题目信息
题号
2061I
时间限制
4 s
内存限制
512 MB
标签
分治
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。