#BS0000340. Bảo đảm trúng cử (How to Win the Election)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bảo đảm trúng cử (How to Win the Election)
How to Win the Election
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
An election has candidates and ballots. Candidate i currently has counted votes. After all votes are counted, a candidate wins exactly when fewer than other candidates have strictly more votes. Tied candidates are not counted as having more votes. Let . For each candidate i find the smallest nonnegative integer X at most R such that receiving exactly X of the remaining votes guarantees victory under every distribution of the other R-X votes. Report -1 if this cannot be guaranteed.
Input
First line: . Second line: integers .
Output
Print integers in the original candidate order.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; or .
- Subtask 3 (50 points): ; ; ; .
Examples
Input 1
5 2 16
3 1 4 1 5
Output 1
2 -1 1 -1 0
Explanation
Two ballots remain. Candidate 1 needs both; with 5 votes there cannot be two candidates above 5. With only one additional vote, candidates 3 and 5 can both have 5. Candidates 2 and 4 cannot guarantee victory even with both remaining votes. Candidate 3 needs one, and candidate 5 is already safe.
Input 2
3 3 10
1 2 3
Output 2
0 0 0
Explanation
Every candidate has fewer than three opponents, so all are guaranteed to win.