Problem Statement There is a grid with H rows and W columns. Let (i,j) denote the cell…
- User
Problem Statement There is a grid with H rows and W columns. Let (i,j) denote the cell at the i-th row from the top and j-th column from the left.
There are N coins on this grid, and the i-th coin can be picked up by passing through the cell (R i ,C i ).
Your goal is to start from cell (1,1), repeatedly move either down or right by one cell, and reach cell (H,W) while picking up as many coins as possible.
Find the maximum number of coins you can pick up and one of the paths that achieves this maximum.
Constraints 2≤H,W≤2×10 5
1≤N≤min(HW−2,2×10 5 ) 1≤R i ≤H 1≤C i ≤W (R i ,C i ) =(1,1) (R i ,C i ) =(H,W) (R i ,C i ) are pairwise distinct. All input values are integers. Input The input is given from Standard Input in the following format:
H W N R 1
C 1
R 2
C 2
⋮ R N
C N
Output Print two lines. The first line should contain the maximum number of coins you can pick up. The second line should contain one of the paths that achieves this maximum as a string of length H+W−2. The i-th character of this string should be D if the i-th move is downward, and R if it is rightward.
If there are multiple paths that maximize the number of coins picked up, you may print any of them.
- Assistant