Gambling Assistant

Time limit: 0.4s Memory limit: 32MB Input: Output:

Task

Giorgio has been recently introduced to a gambling club, where he is accurately losing all of his money. Tired of losing so much, he chooses one of the simplest games played there and tries his best to become good at it. This game consists in a series of NN rounds, in which every player draws a card from a deck (represented by a number from 11 to 1313). The hand size is limited to KK cards, so that whenever a player exceeds this limit he has to immediately discard one card from his hand. During the game several bets take place, that are won by the player with the highest grand total (sum of the values - from 11 to 1313 - of each card) in his hand.

To improve his performance in the game, Giorgio is reviewing some videos of famous plays of this game. In this videos he is able to see which card CiC_i is drawn at each round, but he is not able to easily keep track of the grand total as it varies during the game. Help Giorgio in determining the highest grand total GiG_i that a player can have at each round, given the list of cards CiC_i drawn!

Input data

The first line contains the two integers NN and KK. The second line contains NN integers CiC_i.

Output data

You need to write a single line with NN integers GiG_i, the highest grand total possible when drawing the given cards.

Constraints and clarifications

  • 1KN10000001 \le K \le N \le 1\,000\,000.
  • 1Ci131 \le C_i \le 13 for each i=0N1i=0\ldots N-1.
  • The constraints shown in PDF are wrong.
# Points Constraints
1 5 Examples.
2 10 N=KN = K
3 10 K=1K = 1
4 30 N100N \le 100
5 25 N10000N \le 10\,000
6 20 No additional limitations.

Example 1

stdin

4 2
10 4 10 12

stdout

10 14 20 22

Explanation

In the first sample case, the hands kept by the player (in order) are: [10],[4,10],[10,10],[10,12][10], [4, 10], [10, 10], [10, 12].

Example 2

stdin

8 5
4 13 10 2 7 1 13 7

stdout

4 17 27 29 36 36 47 50

Explanation

In the second sample case, the hands kept by the player (in order) are: [4][4], [4,13][4, 13], [4,10,13][4, 10, 13], [2,4,10,13][2, 4, 10, 13], [2,4,7,10,13][2, 4, 7, 10, 13], [2,4,7,10,13][2, 4, 7, 10, 13], [4,7,10,13,13][4, 7, 10, 13, 13], [7,7,10,13,13][7, 7, 10, 13, 13].

Log in or sign up to be able to send submissions!