専門家として100倍詳しく解説して 「Problem Statement An election is being held with N candidates…
- User
専門家として100倍詳しく解説して 「Problem Statement An election is being held with N candidates numbered 1,2,…,N. There are K votes, some of which have been counted so far.
Up until now, candidate i has received A i votes.
After all ballots are counted, candidate i (1≤i≤N) will be elected if and only if the number of candidates who have received more votes than them is less than M. 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,…,N.
Determine if there is a non-negative integer X not exceeding K− i=1 ∑ N A i satisfying the following condition. If it exists, find the minimum possible such integer.
If candidate i receives X additional votes, then candidate i will always be elected. Constraints 1≤M≤N≤2×10 5
1≤K≤10 12
0≤A i ≤10 12
i=1 ∑ N A i ≤K All input values are integers. Input The input is given from Standard Input in the following format:
N M K A 1
A 2
… A N
Output Let C i be the minimum number of additional votes candidate i needs from the remaining ballots to guarantee their victory regardless of how other candidates receive votes. Print C 1 ,C 2 ,…,C N separated by spaces.
If candidate i has already secured their victory, then let C i =0. If candidate i cannot secure their victory under any circumstances, then let C i =−1.
Sample Input 1 Copy 5 2 16 3 1 4 1 5 Sample Output 1 Copy 2 -1 1 -1 0 14 votes have been counted so far, and 2 votes are left. The C to output is (2,−1,1,−1,0). For example:
Candidate 1 can secure their victory by obtaining 2 more votes, while not by obtaining 1 more vote. Thus, C 1 =2. Candidate 2 can never (even if they obtain 2 more votes) secure their victory, so C 2 =−1.」
- Assistant