#arc178c. C - Sum of Abs 2

C - Sum of Abs 2

Score : 600600 points

问题陈述

给定正整数 NNLL,以及长度为 NN 的正整数序列 A=(A1,A2,,AN)A = (A_{1}, A_{2}, \dots , A_{N})

对于每个 i=1,2,,Ni = 1, 2, \dots , N,回答以下问题:

确定是否存在一个非负整数序列 B=(B1,B2,,BL)B = (B_{1}, B_{2}, \dots, B_{L}),使得 $\displaystyle \sum_{j = 1} ^ {L - 1} \sum_{k = j + 1} ^ {L} |B_{j} - B_{k}| = A_{i}$。如果存在,找到这样的序列 BBmax(B)\max(B) 的最小值。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given positive integers NN and LL, and a sequence of positive integers A=(A1,A2,,AN)A = (A_{1}, A_{2}, \dots , A_{N}) of length NN.

For each i=1,2,,Ni = 1, 2, \dots , N, answer the following question:

Determine if there exists a sequence of LL non-negative integers B=(B1,B2,,BL)B = (B_{1}, B_{2}, \dots, B_{L}) such that $\displaystyle \sum_{j = 1} ^ {L - 1} \sum_{k = j + 1} ^ {L} |B_{j} - B_{k}| = A_{i}$. If it exists, find the minimum value of max(B)\max(B) for such a sequence BB.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^{5}
  • 2L2×1052 \leq L \leq 2 \times 10^{5}
  • 1Ai2×1051 \leq A_{i} \leq 2 \times 10^{5}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN LL

A1A_{1} A2A_{2} \cdots ANA_{N}

Output

Print NN lines. The kk-th line should contain -1 if no sequence BB satisfies the condition for i=ki=k; otherwise, it should contain the minimum value of max(B)\max(B) for such a sequence BB.

Sample Input 1

2 4
10 5

Sample Output 1

3
-1

For A1=10A_{1} = 10, if we take B=(1,0,2,3)B = (1, 0, 2, 3), then $\displaystyle \sum_{j = 1} ^ {L - 1} \sum_{k = j + 1} ^ {L} |B_{j} - B_{k}| = 10$, where max(B)=3\max(B) = 3. No non-negative integer sequence BB satisfies the condition with max(B)<3\max(B) < 3, so print 33 in the first line.

For A2=5A_{2} = 5, there is no non-negative integer sequence BB that satisfies the condition, so print -1 in the second line.

Sample Input 2

6 8
167 924 167167 167924 116677 154308

Sample Output 2

11
58
10448
10496
7293
9645