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 aiai.
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.
Input
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≤n≤105.
The second line contains (n−1)(n−1) positive integers a1,a2,⋯,an−1a1,a2,⋯,an−1, where 1≤ai≤1041≤ai≤104.
We guarantee that the sum of nn in all test cases is up to 106106.
Output
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.
Example
Input
1 5 2 3 1 4
Output
0 10 20 34 48
Note
The figure below describes the sample test case.
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.
贪心
#include<bits/stdc++.h>
#define ll long long
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int t;
ll sum[maxn];
using namespace std;
inline char nc() {
static char buf [100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read() {
static char c=nc(); int x=0,f=1;
for(;c>'9'||c<'0';c=nc()) if(c=='-') f=-1;
for(;c<='9'&&c>='0';c=nc()) x=(x<<3)+(x<<1)+c-48;
return x*f;
}
int main(){
t = read();
while(t--){
int n;
n = read();
memset(sum, 0, sizeof(sum));
sum[1] = 1;
for(int i = 2; i <= n; i++){
ll a;
a = read();
sum[i] += sum[i - 1] + a;
//cout << sum[i] << " ";
}
//cout << endl;
ll ans = 0;
cout << 0 << " ";
ll cnt = 0;
for(int i = 2; i <= n; i++){
if(i % 2){
ans += cnt;
}
else{
ll u = i / 2;
ans += cnt + sum[n - u + 1] - sum[u];
cnt += sum[n - u + 1] - sum[u];
}
if(i == n)
cout << ans << endl;
else
cout << ans << " ";
}
}
}