#abc303c. C - Dash
C - Dash
Score : points
问题描述
在一个二维平面上,Takahashi 初始位于点 ,并且他的初始生命值为 。在平面上放置了 个恢复生命值的物品;其中第 个物品位于坐标 。
Takahashi 将进行 次移动。第 次移动如下:
- 设  为他当前的坐标。根据  的第  个字符 ,他会消耗  点生命值以移动到以下位置:
- 若  为 
R,则移动到点 ; - 若  为 
L,则移动到点 ; - 若  为 
U,则移动到点 ; - 若  为 
D,则移动到点 。 
 - 若  为 
 - 如果 Takahashi 的生命值变为负数,则他会晕倒并停止移动。否则,如果他移动到的位置上放置有物品,并且他的生命值严格小于 ,那么他会在该位置消耗物品,将生命值恢复至 。
 
确定 Takahashi 是否能够在不被晕倒的情况下完成这 次移动。
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
4 2 3 1
RUDL
-1 -1
1 0
Sample Output 1
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 .
Sample Input 2
5 2 1 5
LDRLD
0 0
-1 -1
Sample Output 2
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.
update @ 2024/3/10 08:31:24