#GD0000150. Thu thập bưu kiện (Collecting Packages)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thu thập bưu kiện (Collecting Packages)
Collecting Packages
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A robot starts at on an integer-coordinate grid. There are distinct packages at coordinates , none at the origin. The robot may move one cell right (R) or up (U) per step.
Find a walk that visits every package using the minimum possible number of moves. If several minimum-length walks exist, choose the lexicographically smallest command string (R comes before U).
Input
The first line contains . The next lines each contain coordinates of a package.
Output
Print NO if no walk can collect every package. Otherwise print YES followed by the lexicographically smallest among all shortest command strings made of R and U.
Subtasks
- Subtask 1 (20 points): ; ; points are distinct and different from .
- Subtask 2 (30 points): ; ; points are distinct and different from .
- Subtask 3 (50 points): ; ; points are distinct and different from .
Examples
Input
1
4 3
Output
YES
RRRRUUU
Explanation
A package at requires exactly four R moves and three U moves. The lexicographically smallest shortest path is RRRRUUU, of total length seven.