Codeforces Round 1053 (Div. 2)
C
Incremental Stay
Codeforces
1400
原题
← BD →
翻译中…

You are the security guard of a museum.

翻译中…

The main door of the museum is both an entrance and an exit. At most one person can pass through the door every second. There is a sensor that detects when a visitor passes through the door. The sensor cannot determine neither who the visitor is, nor whether he entered or exited the museum. The sensor detected some activity in $2n$ distinct moments of time $a_1, a_2, \ldots, a_{2n}$ (measured in seconds).

翻译中…

For each visitor, his stay time is equal to the exit time minus the entrance time.

翻译中…

Right now the museum is closed (so it has no visitors), and you wonder about the maximum possible total stay time today, i.e., the maximum possible sum of the stay times of all the visitors that entered the museum today. At second $0$, the museum was closed as well.

翻译中…

For security reasons, there is also a limit on the number of people who can stay in the museum simultaneously, but you forgot this limit. For each $k$ from $1$ to $n$, you want to determine the maximum possible total stay time today, assuming that at most $k$ people can stay in the museum simultaneously.

翻译中…

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 \leq n \leq 2 \cdot 10^5$), indicating that the sensor detected some activity in $2n$ distinct moments of time.

翻译中…

The second line of each test case contains $2n$ integers $a_1, a_2, \ldots, a_{2n}$ ($1 \leq a_1 \lt a_2 \lt \ldots \lt a_{2n} \leq 10^9$) — the seconds when the sensor detected some activity.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, print $n$ integers: for each $k$ from $1$ to $n$, print the maximum possible total stay time today, assuming that at most $k$ people can stay in the museum simultaneously.

翻译中…

Note

翻译中…

In the first test case, the sensor detected activity at seconds $32$ and $78$. Recall that $k$ is the maximum number of people who can stay in the museum simultaneously.

翻译中…
  • If $k$ is $1$, the maximum possible total stay time is $46$, reached if visitor $1$ enters at time $32$ and exits at time $78$.
翻译中…

In the second test case, the sensor detected activity at seconds $4$, $5$, $6$, and $9$.

翻译中…
  • If $k$ is $1$, the maximum possible total stay time is $4$, reached if visitor $1$ enters at time $4$ and exits at time $5$, and visitor $2$ enters at time $6$ and exits at time $9$.
  • If $k$ is $2$, the maximum possible total stay time is $6$, reached if visitor $1$ enters at time $4$ and exits at time $9$, and visitor $2$ enters at time $5$ and exits at time $6$.
翻译中…

样例

Input #1
3
1
32 78
2
4 5 6 9
4
6149048 26582657 36124499 43993239 813829899 860114890 910238130 913669539
Output #1
46
4 6
78018749 1737022233 1845329695 3385003015
InputCopy OutputCopy
题目信息
题号
2151C
时间限制
2 s
内存限制
256 MB
标签
贪心
模拟
数学

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