#abc373e. E - How to Win the Election

E - How to Win the Election

Score : 500500 points

问题陈述

正在进行一场选举,有 NN 名候选人,编号为 1,2,,N1, 2, \ldots, N。共有 KK 张选票,其中一些已经被计算。

到目前为止,候选人 ii 已经收到了 AiA_i 张选票。

在所有选票都被计算之后,候选人 ii (1iN)(1 \leq i \leq N) 只有在收到比他们更多的选票的候选人数量少于 MM 时才会当选。可能会有多个候选人当选。

对于每位候选人,找出他们需要从剩余选票中获得的最少额外选票数,以确保他们的胜利,不管其他候选人如何获得选票。

形式上,为每个 i=1,2,,Ni = 1,2,\ldots,N 解决以下问题。

确定是否存在一个非负整数 XX,不超过 Ki=1NAiK - \displaystyle{\sum_{i=1}^{N}} A_i 满足以下条件。如果存在,找出可能的最小整数。

  • 如果候选人 ii 获得 XX 张额外选票,那么候选人 ii 将总是当选。

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

Problem Statement

An election is being held with NN candidates numbered 1,2,,N1, 2, \ldots, N. There are KK votes, some of which have been counted so far.

Up until now, candidate ii has received AiA_i votes.

After all ballots are counted, candidate ii (1iN)(1 \leq i \leq N) will be elected if and only if the number of candidates who have received more votes than them is less than MM. There may be multiple candidates elected.

For each candidate, find the minimum number of additional votes they need from the remaining ballots to guarantee their victory regardless of how the other candidates receive votes.

Formally, solve the following problem for each i=1,2,,Ni = 1,2,\ldots,N.

Determine if there is a non-negative integer XX not exceeding Ki=1NAiK - \displaystyle{\sum_{i=1}^{N}} A_i satisfying the following condition. If it exists, find the minimum possible such integer.

  • If candidate ii receives XX additional votes, then candidate ii will always be elected.

Constraints

  • 1MN2×1051 \leq M \leq N \leq 2 \times 10^5
  • 1K10121 \leq K \leq 10^{12}
  • 0Ai10120 \leq A_i \leq 10^{12}
  • i=1NAiK\displaystyle{\sum_{i=1}^{N} A_i} \leq K
  • All input values are integers.

Input

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

NN MM KK

A1A_1 A2A_2 \ldots ANA_N

Output

Let CiC_i be the minimum number of additional votes candidate ii needs from the remaining ballots to guarantee their victory regardless of how other candidates receive votes. Print C1,C2,,CNC_1, C_2, \ldots, C_N separated by spaces.

If candidate ii has already secured their victory, then let Ci=0C_i = 0. If candidate ii cannot secure their victory under any circumstances, then let Ci=1C_i = -1.

Sample Input 1

5 2 16
3 1 4 1 5

Sample Output 1

2 -1 1 -1 0

1414 votes have been counted so far, and 22 votes are left.
The CC to output is (2,1,1,1,0)(2, -1, 1, -1, 0). For example:

  • Candidate 11 can secure their victory by obtaining 22 more votes, while not by obtaining 11 more vote. Thus, C1=2C_1 = 2.
  • Candidate 22 can never (even if they obtain 22 more votes) secure their victory, so C2=1C_2 = -1.

Sample Input 2

12 1 570
81 62 17 5 5 86 15 7 79 26 6 28

Sample Output 2

79 89 111 117 117 74 112 116 80 107 117 106