#P16012. [CCO 2016 Day 2] Pirates

[CCO 2016 Day 2] Pirates

题目描述

A group of NN pirates found KK gold coins. They must decide on a way to distribute the coins amongst themselves. They have agreed on the following rules:

The oldest pirate proposes a distribution. (You can assume that all the pirates' ages are distinct.) A distribution assigns a non-negative integer number of coins to each pirate such that the sum of these numbers equals K.

Then, each pirate will vote either yes or no on the proposal. The number of yes votes required for the proposal to pass depends on the number of pirates. If there are XX pirates, then V[X]V[X] yes votes are required for the proposal to pass. If the proposal passes, the coins are assigned according the proposed distribution and the process ends. Otherwise, the oldest pirate is thrown overboard and the process is repeated without him.

The pirates act according to the following rules. The rules are given in order of priority; for example, rule 22 is only applied to distinguish between multiple options that are optimal according to rule 11.

  1. A pirate will act to prevent himself from being thrown overboard.

  2. A pirate will act to maximize the number of coins he receives.

  3. A pirate will act to maximize the number of pirates thrown overboard (excepting himself, because rule 11 takes priority).

  4. A pirate will act to maximize the number of coins received by the oldest pirate. If there are still multiple choices that fit these rules, he will maximize the gold received by the second-oldest pirate, then the third-oldest pirate, etc.

If there are multiple options that are optimal according to these rules, then the pirate chooses an action arbitrarily. (You can assume that the answer to this problem does not depend on the pirate's choice in this case.) Additionally, all the pirates are perfectly logical and know all the information contained in this problem statement. They cannot form agreements or coalitions because they do not trust each other.

We will number the pirates from 11 to NN, where these are numbered from the youngest (pirate 11) to the oldest (pirate NN).

If there were only ii pirates (where i=1,,Ni = 1, \dots, N), how many coins would the oldest of them get?

输入格式

The first line of input will be the number N (2N106)N\ (2 \le N \le 10^6).

The second line of input will be the integer K (1K1018)K\ (1 \le K \le 10^{18}).

The next NN lines of input contain V[i] (1V[i]i)V[i]\ (1 \le V[i] \le i) indicating the number of yes votes required for a proposal to pass if there are ii pirates remaining (i=1,,N)(i = 1, \dots, N).

For 55 of the 2525 available marks for this problem N2000N \le 2\,000.

For an additional 55 of the 2525 available marks for this problem max(1,i3)V[i]i\max(1, i - 3) \le V[i] \le i for all i=1,,Ni = 1, \dots, N.

For an additional 55 of the 2525 available marks for this problem, K=1018K = 10^{18}.

输出格式

The output should consist of NN integers, printed one per line. The ithi^{th} line of output is the number of coins that the ithi^{th} pirate would get if they were the oldest pirate; in other words, if only pirates 1,,i1, \dots, i existed. If the ithi^{th} pirate is thrown overboard, output 1-1 on the ithi^{th} line.

5
100
1
1
2
2
3
100
100
99
99
98
5
100
1
2
3
4
4
100
-1
-1
-1
100
4
100
1
1
2
3
100
100
99
97
4
2
1
1
2
3
2
2
1
-1

提示

Explanation for Sample Output 11

If there are 22 pirates left, pirate 22 can propose that all of the gold coins go to him. Only 11 vote is required for this proposal to pass, so he can guarantee that it passes by voting for it.

If there are 33 pirates left, pirate 33 needs someone else to vote for his proposal. He can ensure this by giving 11 coin to pirate 11 and 9999 to himself. Pirate 11 knows that if the proposal doesn't pass, he will receive nothing. So a single coin is enough to secure his vote.

If there are 44 pirates left, pirate 44 gives 11 gold coin to pirate 22 and 99 to himself.

If there are 55 pirates left, pirate 55 gives 11 gold coin to pirates 11 and 33 and keeps 9898 coins for himself.

Explanation for Sample Output 22

In this case, a full consensus is required for a proposal to pass, except when there are 55 pirates, in which case only 44 of the 55 votes are required.

If there is full consensus required, and there are 22 or more pirates, the youngest pirate will vote against the proposal to maximize their coins and also throw the most pirates overboard.

In the case where there are 55 pirates, the oldest pirate will propose to give himself 100100 coins. Everyone except the youngest pirate will vote yes, because if this proposal doesn't pass, the youngest pirate will get all of them thrown overboard and then take the coins for himself when only he remains. Since the pirates don't want to be thrown overboard, they will vote yes, even though the oldest pirate will offer them nothing.

Explanation for Sample Output 33

The first three cases were explained in Sample Input 11. When there are 44 pirates, the oldest pirate needs 33 votes. He will give 22 coins to the youngest pirate and 11 coin to the second-youngest pirate, keeping the rest for himself.

Explanation for Sample Output 44

The situation is the same as in Example 33, but now there are only 22 coins. With 11, 22 or 33 pirates, we have the same situations as in Example 33.

With 44 pirates, the oldest pirate does not have enough coins to ensure the 33 votes which he needs, so he will be thrown overboard.