#BS0000215. Thu thập đồng xu (Gather Coins)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thu thập đồng xu (Gather Coins)
Gather Coins
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A grid contains rows and columns. Cell lies in row from the top and column from the left. There are coins at distinct cells ; neither nor contains a coin.
Starting at , you may move one cell down or right at each step, staying in the grid. Collect the coin whenever you visit its cell. Reach while collecting as many coins as possible, and provide one route achieving that maximum.
Input
The first line contains three integers . The -th of the next lines contains two integers , the coordinates of coin .
Output
Print two lines. The first contains the maximum number of coins. The second contains a string of exactly characters describing a route, using D for down and R for right. Any optimal route is accepted.
Subtasks
- Subtask 1 (20 points): ; ; , for every ; coin cells are distinct and neither endpoint contains a coin.
- Subtask 2 (30 points): ; ; , for every ; coin cells are distinct and neither endpoint contains a coin.
- Subtask 3 (50 points): ; ; , for every ; coin cells are distinct and neither endpoint contains a coin.
Examples
Input
3 4 4
3 3
2 1
2 3
1 4
Output
3
DRRDR
Explanation
Route DRRDR visits and collects coins at . Coin cannot be combined with those three without moving up or left. Thus three is optimal.

Input
2 2 2
2 1
1 2
Output
1
DR
Explanation
Route DR collects the coin at , while RD collects the coin at . A down/right route cannot visit both, so both routes are optimal.