Ограничения: время – 250ms/500ms, память – 256MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод
Послать решение Blockly Посылки Темы Где Обсудить (0)
No Thanks! is a card game for three to five players designed by Thorsten Gimmler and originally called Geschenkt!
There are playing cards numbered 3 to 35 in the game, and nine cards are chosen at random and removed from the deck, which is then shuffled.
Each player starts with 11 chips.
The first player flips over the top card and either takes it (earning that player points according to the value) or passes on
the card by paying a chip (placing it on the card) and saying, "No thanks!"
Play then proceeds in a clockwise circle until someone finally takes the card along with all of its accumulated chips,
if any. That same player then flips over the next card, also deciding on whether to take the card or pass it, and so the
game continues until all cards have been taken.
At the end of the game, players accrue points from cards according to their value, but cards in a row only count as
a single card with the lowest value (e.g., a run with cards numbered 30, 29, 28, 27 is worth 27 points). Chips are worth *one
negative point* each. The player(s) with the lowest number of points win(s) the game.
Your job is to compute the score for a single player’s pile of cards.
The first line contains two integers, `n` (`1 <= n <= 10^5`), representing the number of cards collected, and `m` (`0 <= m <= 10^5`),
representing the number of player's chips.
The second line contains `n` integers representing the numbers on the collected cards.
All card values are in the range `1...10^5` inclusive, and no card value is repeated.
Output a single line containing the score for the given set of cards.
```sample Sample Input 1
5 0
1 3 7 5 4
```
```sample Sample Output 1
11
```
```sample Sample Input 2
6 10
2 8 1 3 4 5
```
```sample Sample Output 2
-1
```