PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000012. Dãy con tăng - bản dễ (Increasing Subsequence - Easy Version)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dãy con tăng - bản dễ (Increasing Subsequence - Easy Version)
Increasing Subsequence (Easy Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of pairwise distinct positive integers, containing every value from to exactly once. In each move, take either the leftmost or the rightmost element of the current sequence, append its value to the result, and remove it from the original sequence.
The selected values must form a strictly increasing sequence: each new value must be greater than the preceding one. You may stop at any moment. Maximize the number of moves and output a sequence of moves achieving this maximum.
Input
- The first line contains an integer , the initial sequence length.
- The second line contains integers from left to right.
Output
- Print the maximum number of moves on the first line.
- Print a string of exactly characters on the second line:
Lfor a left-end move andRfor a right-end move. Any optimal string is accepted.
Subtasks
- Subtask 1 (20 points): ; for every ; is a permutation of .
- Subtask 2 (30 points): ; for every ; is a permutation of .
- Subtask 3 (50 points): ; for every ; is a permutation of .
Examples
Input
5
2 1 5 4 3
Output
4
LRRR
Explanation
Take left 2, then right 3, right 4, and right 5, obtaining the strictly increasing sequence 2,3,4,5. The remaining 1 cannot be appended.