Woburn Challenge 2016-17 Round 2 - Senior Division
Lieutenant commander Scetty has been assigned quite the tedious task - testing a turbolift. Hardly a job worthy of the Enterprise's chief engineer! This particular turbolift has just buttons - one to take the turbolift up floor, and another to take it down floor.
One "button press" is an action consisting of, well, pressing one of the
buttons. It can be represented as a single character, either U
if
the up button is pressed, or D
if the down button is pressed.
One "button sequence" is an ordered sequence of one or more button presses. The turbolift has the ability to perform different types of button sequences, numbered from to , with the one represented by the string . The character in this string represents the button press in the sequence. The strings are not necessarily distinct, and the sum of their lengths is at most .
The turbolift will start on floor of the Enterprise. Due to recent technological advances, the ship has infinitely many floors above floor (numbered upwards from ), and infinitely many basement floors below it (numbered downwards from ). As part of the testing process, it will then be programmed to execute button sequences, one after another. The button sequence in this sequence of sequences will be button sequence is . Note that some button sequences could be executed multiple times during the testing, while others could not be executed at all.
Throughout the process, Scetty will make notes about how low and high the turbolift ends up getting. In particular, he has questions to answer. The one asks: "After the first button presses, what are the minimum and maximum floor numbers that the turbolift will have reached up to that point?". is a positive integer no greater than the total number of button presses which will be executed throughout the sequence of button sequences. Note that both and the answers may not fit within a -bit integer.
In test cases worth of the points, , , and no single button sequence consists of more than button presses.
Input Specification
The first line of input consists of three space-separated integers ,
, and .
lines follow, the of which consists of a single string
(for ).
lines follow, the of which consists of a single integer
(for ).
lines follow, the of which consists of a single integer
(for ).
Output Specification
Output lines, the of which should consist of two space-separated integers - the lowest and highest floors that the turbolift will reach after no more than button presses (for ).
Sample Input
2 3 3
DDUU
U
2
1
2
1
6
4
Sample Output
0 1
-1 2
-1 1
Sample Explanation
The turbolift will receive button presses in total, with the following results:
Button | Floor
-------+------
U | 1
D | 0
D | -1
U | 0
U | 1
U | 2
Comments