atcoder#ABC303C. [ABC303C] Dash

[ABC303C] Dash

Score : 300300 points

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.

4 2 3 1
RUDL
-1 -1
1 0
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.

5 2 1 5
LDRLD
0 0
-1 -1
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.