#P17474. [ICPC 2018 Jiaozuo R] Distance

    ID: 16846 Type: RemoteJudge 6000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>动态规划 DP贪心2018前缀和ICPC

[ICPC 2018 Jiaozuo R] Distance

题目描述

There are nn points on a horizontal line, labelled with 11 through nn from left to right.

The distance between the ii-th point and the (i+1)(i + 1)-th point is aia_i.

For each integer kk ranged from 11 to nn, you are asked to select exactly kk different given points on the line to maximize the sum of distances between all pairs of selected points.

输入格式

The input contains several test cases, and the first line contains a positive integer TT indicating the number of test cases which is up to 10001000.

For each test case, the first line contains an integer nn indicating the number of points, where 2≤n≤1052 \leq n \leq 10^5.

The second line contains (n−1)(n - 1) positive integers a1,a2,⋯ ,an−1a_1, a_2, \cdots, a_{n - 1}, where 1≤ai≤1041 \leq a_i \leq 10^4.

We guarantee that the sum of nn in all test cases is up to 10610^6.

输出格式

For each test case, output a line containing nn integers, the ii-th of which is the maximum sum of distances in case k=ik = i. You should output exactly one whitespace between every two adjacent numbers and avoid any trailing whitespace in this line.

1
5
2 3 1 4
0 10 20 34 48

提示

The figure below describes the sample test case.

:::align{center} :::

The only best selection for k=2k = 2 should choose the leftmost and the rightmost points, while a possible best selection for k=3k = 3 could contain any extra point in the middle.