Official algorithmic problem description and constraints.
Alice and Bob are playing a board game.
On their turn, a player must roll 𝑁 standard 6-sided dice, and their action will be determined by the sum of values on the top faces of the 𝑁 dice.
On a certain turn of Alice, she rolls the dice and obtains the sequence of values 𝐴1,𝐴2,…,𝐴𝑁 on the top faces.
However, Bob isn't paying attention, allowing Alice to cheat a little!
Alice can choose a die, and flip it - so the opposite face is upward.
So as to not make Bob suspicious, Alice can perform this flipping operation at most 𝐾 times.
What's the maximum score (i.e, sum of values of top faces of the dice) she can obtain?
Detailed video explanations, mathematical intuition, and clean C++ implementation code.