#abc303c. C - Dash

C - Dash

Score : 300300 points

问题描述

在一个二维平面上,Takahashi 初始位于点 (0,0)(0, 0),并且他的初始生命值为 HH。在平面上放置了 MM 个恢复生命值的物品;其中第 ii 个物品位于坐标 (xi,yi)(x_i,y_i)

Takahashi 将进行 NN 次移动。第 ii 次移动如下:

  1. (x,y)(x,y) 为他当前的坐标。根据 SS 的第 ii 个字符 SiS_i,他会消耗 11 点生命值以移动到以下位置:
    • SiS_iR,则移动到点 (x+1,y)(x+1,y)
    • SiS_iL,则移动到点 (x1,y)(x-1,y)
    • SiS_iU,则移动到点 (x,y+1)(x,y+1)
    • SiS_iD,则移动到点 (x,y1)(x,y-1)
  2. 如果 Takahashi 的生命值变为负数,则他会晕倒并停止移动。否则,如果他移动到的位置上放置有物品,并且他的生命值严格小于 KK,那么他会在该位置消耗物品,将生命值恢复至 KK

确定 Takahashi 是否能够在不被晕倒的情况下完成这 NN 次移动。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

On a two-dimensional plane, Takahashi is initially at point (0,0)(0, 0), and his initial health is HH. MM items to recover health are placed on the plane; the ii-th of them is placed at (xi,yi)(x_i,y_i).

Takahashi will make NN moves. The ii-th move is as follows.

  1. Let (x,y)(x,y) be his current coordinates. He consumes a health of 11 to move to the following point, depending on SiS_i, the ii-th character of SS:

    • (x+1,y)(x+1,y) if SiS_i is R;
    • (x1,y)(x-1,y) if SiS_i is L;
    • (x,y+1)(x,y+1) if SiS_i is U;
    • (x,y1)(x,y-1) if SiS_i is D.
  2. 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 KK, then he consumes the item there to make his health KK.

Determine if Takahashi can complete the NN moves without being stunned.

Constraints

  • 1N,M,H,K2×1051\leq N,M,H,K\leq 2\times 10^5
  • SS is a string of length NN consisting of R, L, U, and D.
  • xi,yi2×105|x_i|,|y_i| \leq 2\times 10^5
  • (xi,yi)(x_i, y_i) are pairwise distinct.
  • All values in the input are integers, except for SS.

Input

The input is given from Standard Input in the following format:

NN MM HH KK

SS

x1x_1 y1y_1

\vdots

xMx_M yMy_M

Output

Print Yes if he can complete the NN 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 33. We describe the moves below.

  • 11-st move: SiS_i is R, so he moves to point (1,0)(1,0). His health reduces to 22. Although an item is placed at point (1,0)(1,0), he do not consume it because his health is no less than K=1K=1.

  • 22-nd move: SiS_i is U, so he moves to point (1,1)(1,1). His health reduces to 11.

  • 33-rd move: SiS_i is D, so he moves to point (1,0)(1,0). His health reduces to 00. An item is placed at point (1,0)(1,0), and his health is less than K=1K=1, so he consumes the item to make his health 11.

  • 44-th move: SiS_i is L, so he moves to point (0,0)(0,0). His health reduces to 00.

Thus, he can make the 44 moves without collapsing, so Yes should be printed. Note that the health may reach 00.

Sample Input 2

5 2 1 5
LDRLD
0 0
-1 -1

Sample Output 2

No

Initially, Takahashi's health is 11. We describe the moves below.

  • 11-st move: SiS_i is L, so he moves to point (1,0)(-1,0). His health reduces to 00.

  • 22-nd move: SiS_i is D, so he moves to point (1,1)(-1,-1). His health reduces to 1-1. Now that the health is 1-1, 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 (0,0)(0,0), he does not consume it before the 11-st move, because items are only consumed after a move.

update @ 2024/3/10 08:31:24

}