P3042 [USACO12JAN] Cow Run G
Description
Farmer John and Bessie have devised a new exercise game for the cows. The cows are running on a circular track of length M (2
Input Format
\* Line 1: Three space-separated integers N, M, K
\* Line 2: A string N characters. If the ith character is 'T' it means Bessie will select the top 2 cards in the ith round. Otherwise the ith character will be 'B' to indicate Bessie will select the bottom 2 cards in the ith round.
\* Lines 3..2+N: Each line contains eight integers representing the 8 cards to be used that round from top to bottom.
Output Format
\* Line 1: A string of N characters where the ith character is 'T' if FJ should choose the top 4 cards or 'B' if FJ should choose the bottom 4 cards in the ith round. If there are multiple ways to get the cows home, choose the lexicographically first (that is, the string that is alphabetically smallest).
Explanation/Hint
The cows must end up exactly where they started to be able to come home. Note that FJ is not aware of what choices Bessie is going to make beforehand. If FJ did know, he could have chosen the bottom half each time.