码迷,mamicode.com
首页 > 其他好文 > 详细

I. Distance (模拟)2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest

时间:2019-10-06 00:14:22      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:lib   iostream   ssi   several   oss   seve   col   i+1   out   

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 2n1052≤n≤105.

The second line contains (n1)(n−1) positive integers a1,a2,?,an1a1,a2,?,an−1, where 1ai1041≤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 <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
typedef long long lli;
using namespace std;
multiset<int> mu;
    #define fi      first
    #define se      second
    #define pb      push_back
    #define pql     priority_queue<lli>
    #define pq      priority_queue<int>
    #define ok      return 0;
    #define oi(x)   cout<<x<<endl;
    #define os(str) cout<<string(str)<<endl;
using namespace std;
//multiset<int> :: iterator it ;
//int dir[6][3] = {0,0,1,0,0,-1,1,0,0,-1,0,0,0,1,0,0,-1,0};           //三维六向
//int dir[8][2] = {2,1,2,-1,-2,1,-2,-1,1,2,1,-2,-1,2,-1,-2};          //马走日
//int dir[4][2] = {1,0,-1,0,0,1,0,-1};                                //二维四向
//int dir[8][2]={1,0,1,1,1,-1,-1,0,-1,1,-1,-1,0,1,0,-1};              //全方位
#define en(xx) xx.begin(),xx.end()
#define rep(j,k) for (int i = j;   i < k;  i++)
#define per(j,k) for (int i = j-1; i >= k; i--)
  typedef pair < int, int > pii;
  typedef pair < lli, lli > pll;
  typedef vector < lli > vl;
  typedef vector < int > vi;
#define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
const int mxn = 2e5 + 10;
lli t,n,l,r,cnt,a[mxn],c[mxn];
int main()
{
    TLE;
    cin>>t;
    while(t--)
    {
        cin >> n;
        a[1] = 0;
        for(int i = 2; i <= n; i++)
        {
            cin>>a[i];
            a[i]+=a[i-1];
        }
        l = 2,r = n - 1;
        c[1] = 0,c[2] = a[n];
        cnt = a[n];
        for(int i = 3; i <= n; i++)
        {
            if(i & 1)
            {
                c[i] = c[i-1] + cnt;
            }
            else
            {
                cnt += a[r] - a[l];
                c[i] = c[i-1] + cnt;
                l++;r--;
            }
        }
        cout<<c[1];
        for(int i = 2; i <=n; i++)
        {
            cout<<" "<< c[i];
        }
        cout << endl;
    }
    
    return 0;
}

 

I. Distance (模拟)2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest

标签:lib   iostream   ssi   several   oss   seve   col   i+1   out   

原文地址:https://www.cnblogs.com/Shallow-dream/p/11626018.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!