#abc373e. E - How to Win the Election
E - How to Win the Election
Score : points
问题陈述
正在进行一场选举,有 名候选人,编号为 。共有 张选票,其中一些已经被计算。
到目前为止,候选人 已经收到了 张选票。
在所有选票都被计算之后,候选人 只有在收到比他们更多的选票的候选人数量少于 时才会当选。可能会有多个候选人当选。
对于每位候选人,找出他们需要从剩余选票中获得的最少额外选票数,以确保他们的胜利,不管其他候选人如何获得选票。
形式上,为每个 解决以下问题。
确定是否存在一个非负整数 ,不超过 满足以下条件。如果存在,找出可能的最小整数。
- 如果候选人 获得 张额外选票,那么候选人 将总是当选。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
An election is being held with candidates numbered . There are votes, some of which have been counted so far.
Up until now, candidate has received votes.
After all ballots are counted, candidate will be elected if and only if the number of candidates who have received more votes than them is less than . 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 .
Determine if there is a non-negative integer not exceeding satisfying the following condition. If it exists, find the minimum possible such integer.
- If candidate receives additional votes, then candidate will always be elected.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Let be the minimum number of additional votes candidate needs from the remaining ballots to guarantee their victory regardless of how other candidates receive votes. Print separated by spaces.
If candidate has already secured their victory, then let . If candidate cannot secure their victory under any circumstances, then let .
Sample Input 1
5 2 16
3 1 4 1 5
Sample Output 1
2 -1 1 -1 0
votes have been counted so far, and votes are left.
The to output is . For example:
- Candidate can secure their victory by obtaining more votes, while not by obtaining more vote. Thus, .
- Candidate can never (even if they obtain more votes) secure their victory, so .
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