High Card Low Card
Time limit2sMemory limit512 MB
Order Bessie's cards against Elsie's known sequence to win the most rounds under high-card-first-half and low-card-second-half scoring.
Problem
Bessie the cow loves card games, which is a surprising hobby for an animal with no opposable thumbs. The trouble is that none of the other cows in the herd make decent opponents. They play so badly that their order of play is completely predictable. Even then, finding a winning line is not easy for Bessie.
Bessie and her friend Elsie play a simple card game. They take a deck of cards numbered through and split it so that Bessie holds cards and Elsie holds cards. They play rounds, and in each round each player puts down one card. In the first rounds the player with the higher card scores one point. In the last rounds the rule flips and the player with the lower card scores one point. All card numbers are distinct, so no round is a tie.
Bessie knows in advance the order in which Elsie will play her cards. Bessie may play her own cards in any order she likes. Write a program that computes the maximum number of points Bessie can score.
Input
The first line contains (, and is even).
Each of the next lines contains one card that Elsie plays, given in round order. The cards missing from this list are exactly Bessie's hand.
Output
Print the maximum number of points Bessie can score on a single line.
Hint
In the example with where Elsie plays , , , , Bessie holds , , , and . She beats the with her in the first round, then saves the for one of the last two rounds, where it beats the or the . Two points is the most she can get.