PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000340. Bảo đảm trúng cử (How to Win the Election)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 NN candidates and KK ballots. Candidate i currently has AiA_i counted votes. After all votes are counted, a candidate wins exactly when fewer than MM other candidates have strictly more votes. Tied candidates are not counted as having more votes. Let R=K−∑AiR=K-\sum A_i. 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: N,M,KN,M,K. Second line: NN integers AiA_i.

Output

Print NN integers in the original candidate order.

Subtasks

  • Subtask 1 (20 points): 1≤M≤N≤51\le M\le N\le5; 1≤K≤201\le K\le20; 0≤Ai≤K0\le A_i\le K; ∑Ai≤K\sum A_i\le K; R≤8R\le8.
  • Subtask 2 (30 points): 1≤M≤N≤2⋅1051\le M\le N\le2\cdot10^5; 1≤K≤10121\le K\le10^{12}; 0≤Ai≤K0\le A_i\le K; ∑Ai≤K\sum A_i\le K; M=1M=1 or M=NM=N.
  • Subtask 3 (50 points): 1≤M≤N≤2⋅1051\le M\le N\le2\cdot10^5; 1≤K≤10121\le K\le10^{12}; 0≤Ai≤K0\le A_i\le K; ∑Ai≤K\sum A_i\le K.

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.