Gather Coins

AtCoder
IDabc369_f
Time2000ms
Memory256MB
Difficulty
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\leq H,W \leq 2\times 10^5$ * $1\leq N \leq \min(HW-2, 2\times 10^5)$ * $1\leq R_i \leq H$ * $1\leq C_i \leq W$ * $(R_i,C_i)\neq (1,1)$ * $(R_i,C_i)\neq (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$ $\vdots$ $R_N$ $C_N$ [samples]
Samples
Input #1
3 4 4
3 3
2 1
2 3
1 4
Output #1
3
DRRDR

![image](https://img.atcoder.jp/abc369/8c45374379376c75b6cfd44cb8efeaf8.png)
As shown in the figure above, by moving $(1,1)\rightarrow (2,1)\rightarrow (2,2)\rightarrow (2,3)\rightarrow (3,3)\rightarrow (3,4)$, you can pick up three coins at $(2,1),(2,3),(3,3)$.
Input #2
2 2 2
2 1
1 2
Output #2
1
DR

The path `RD` is also acceptable.
Input #3
10 15 8
2 7
2 9
7 9
10 3
7 11
8 12
9 6
8 1
Output #3
5
DRRRRRRRRDDDDDRRDRDDRRR
API Response (JSON)
{
  "problem": {
    "name": "Gather Coins",
    "description": {
      "content": "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 ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc369_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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.\nThere are $N$ coins on this grid, and the $i$\\-th coin can ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments