MONOPOLY
Time limit: 5 seconds
Problem
![](monopoly.jpg)
Randel and Ted are playing the MONOPOLY game. Whenever a player arrives at a piece of unsold land, he/she will pay $L to buy it as long as he/she has enough money. If player A arrives at a piece of land owned by another player B, A has to pay a fixed rent $R to B. If at any point of the game, a player has to pay the rent $R but does not have enough money to do so, the player goes bankrupt and loses the game. The game then ends. For simplicity, the players are unable to do mortgages.
Initially, each player has $N. Randel moves first and then they move alternately. There are M moves in total.
Given the list of places each player moves to in each around, you are asked to find out which player loses. If neither player loses, you have to output the money they have at the end of all the moves.
Input
The input starts with a line containing an integer 1 <= n <= 20.
Then n cases follow.
For each test case, the first line contains four non-negative integers N, L, R, M, where N <= 300,000,000 and M <= 30,000.
The following M lines containing the places Randel and Ted moves to, alternately, in sequence.
Output
For each test case,
if one of the player goes bankrupt, output "Yes" in the first line, and the loser's name in the second line.
Otherwise, output "No" in the first line, the money Randel and Ted has at the end, respectively, on the second and third line.
Sample Input
2
5 4 1 4
Nathan Road
Sai Yee Street
Sai Yee Street
Nathan Road
5 5 1 3
Nathan Road
Sai Yee Street
Sai Yee Street
Sample Output
No
1
1
Yes
Randel
Explanation for first test case:
The money Randel and Ted has respectively:
At the beginning: 5 5
After Randel buys Nathan Road: 1 5
After Ted buys Sai Yee Street: 1 1
After Randel pays the rent at Sai Yee Street: 0 2
After Ted pays the rent at Nathan Road: 1 1
Author
Kelly Choi