atcoder#ABC303C. [ABC303C] Dash
[ABC303C] Dash
Score : points
Problem Statement
On a two-dimensional plane, Takahashi is initially at point , and his initial health is . items to recover health are placed on the plane; the -th of them is placed at .
Takahashi will make moves. The -th move is as follows.
- Let be his current coordinates. He consumes a health of to move to the following point, depending on , the -th character of :
- if is
R
; - if is
L
; - if is
U
; - if is
D
.
- if is
- If Takahashi's health has become negative, he collapses and stops moving. Otherwise, if an item is placed at the point he has moved to, and his health is strictly less than , then he consumes the item there to make his health .
Determine if Takahashi can complete the moves without being stunned.
Constraints
- is a string of length consisting of
R
,L
,U
, andD
. - are pairwise distinct.
- All values in the input are integers, except for .
Input
The input is given from Standard Input in the following format:
Output
Print Yes
if he can complete the moves without being stunned; print No
otherwise.
4 2 3 1
RUDL
-1 -1
1 0
Yes
Initially, Takahashi's health is . We describe the moves below.
- -st move: is
R
, so he moves to point . His health reduces to . Although an item is placed at point , he do not consume it because his health is no less than . - -nd move: is
U
, so he moves to point . His health reduces to . - -rd move: is
D
, so he moves to point . His health reduces to . An item is placed at point , and his health is less than , so he consumes the item to make his health . - -th move: is
L
, so he moves to point . His health reduces to .
Thus, he can make the moves without collapsing, so Yes
should be printed. Note that the health may reach .
5 2 1 5
LDRLD
0 0
-1 -1
No
Initially, Takahashi's health is . We describe the moves below.
- -st move: is
L
, so he moves to point . His health reduces to . - -nd move: is
D
, so he moves to point . His health reduces to . Now that the health is , he collapses and stops moving.
Thus, he will be stunned, so No
should be printed.
Note that although there is an item at his initial point , he does not consume it before the -st move, because items are only consumed after a move.