PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000013. Dãy con tăng - bản khó (Increasing Subsequence - Hard 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 khó (Increasing Subsequence - Hard Version)
Increasing Subsequence (Hard Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of positive integers. At each move, take either the leftmost or the rightmost remaining element, append its value to the result, and remove it from the sequence.
The resulting values must be strictly increasing. You may stop early and want to take as many elements as possible. Unlike the easy version, input values may be equal. Find the maximum possible number of moves and print a string of moves achieving that maximum.
Input
- The first line contains integer , the length of the sequence.
- The second line contains exactly integers in their original order.
Output
- The first line contains the maximum possible length of a strictly increasing sequence.
- The second line contains a string of length consisting of
LandRin move order. Any optimal answer is allowed.
Subtasks
- Subtask 1 (20 points): ; for every ; values may repeat.
- Subtask 2 (30 points): ; for every ; values may repeat.
- Subtask 3 (50 points): ; for every ; values may repeat.
Examples
Input
5
1 2 4 3 2
Output
4
LRRR
Explanation
Choose left 1, then right 2, right 3, and right 4 to obtain 1,2,3,4. When endpoints match, compare the increasing runs available in both directions.