Problem E
King of Spades
“King of Spades” is a two-player card game which is played with an unconventionally large deck composed of standard playing cards. The game is set up by splitting the deck into two arbitrary piles, and then the cards from each pile are laid face-up in a line.
![\includegraphics[width=0.4\textwidth ]{image}](/problems/kingofspades/file/statement/en/img-0001.png)
A player’s turn involves choosing a contiguous range of
On a given turn, if at least one King of Spades is chosen,
then absolutely no points are earned. It must also be the case
that the two chosen ranges are ‘similar’, or else no points are
earned. Two ranges of cards are defined to be similar if and
only if each suit and each rank is found in both ranges the
same number of times. If the ranges are similar, then the
number of points earned during that turn is equal to the sum of
the values of all of the cards chosen. A numbered card is worth
its stated value (e.g.,
Due to the sheer number of possible card selections, it is not always easy for a player to find a high-scoring move, so you have been asked to help automate this process. Given an arrangement of cards in two lines, your task is to determine the maximum number of points that a player can earn on that turn.
For example, in the first sample input, a player can achieve
a maximum score of
Input
The first line of input contains two space-separated
integers
Output
The output should contain a single number, indicating the maximum score that can be achieved on that turn.
Sample Input 1 | Sample Output 1 |
---|---|
3 5 5C JC 8H 2H KC 8C JH 8H |
36 |
Sample Input 2 | Sample Output 2 |
---|---|
1 2 4S 2C AH |
0 |
Sample Input 3 | Sample Output 3 |
---|---|
7 6 AC 2H 3D 4D 5C KS 6H 7C 8H KH 6S 9D QD |
0 |