C1. Increasing Subsequence (easy version)

put contains one integer n (1≤n≤2⋅105) — the number of elements in a.

The second line of the input contains n integers a1,a2,…,an (1≤ai≤n), where ai is the i-th element of a. All these integers are pairwise distinct.

Output
In the first line of the output print k — the maximum number of elements in a strictly increasing sequence you can obtain.

In the second line print a string s of length k, where the j-th character of this string sj should be ‘L’ if you take the leftmost element during the j-th move and ‘R’ otherwise. If there are multiple answers, you can print any.

Examples
inputCopy
5
2 1 5 4 3
outputCopy
4
LRRR
inputCopy
7
1 3 5 6 7 4 2
outputCopy
7
LRLRLLL
inputCopy
3
1 2 3
outputCopy
3
LLL
inputCopy
4
1 2 4 3
outputCopy
4
LLRL
Note
The first example is described in the problem statement.

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<vector>
#define ll long long
#define dd double
using namespace std;


int main() {
	ll n;
	while (cin >> n) {
		string s = "";
		ll a[200005];
		for (ll i = 0; i < n; i++) {
			cin >> a[i];
		}
		ll i = 0;
		ll j = n - 1;
		ll max = -1;
		if (a[i] < a[j]) {
			s += 'L';
			max = a[i];
			i++;
		}
		else {
			s += 'R';
			max = a[j];
			j--;
		}
		while (i < j) {
			if (max < a[i] && max < a[j]) {
				if (a[i] < a[j]) {
					s += 'L';
					max = a[i];
					i++;
				}
				else {
					s += 'R';
					max = a[j];
					j--;
				}
			}
			else if (max<a[i] && max>a[j]) {
				s += 'L';
				max = a[i];
				i++;
			}
			else if (max<a[j] && max>a[i]) {
				max = a[j];
				s += 'R';
				j--;
			}
			else {
				break;
			}
		}
		if (i == j && max < a[i]) {
			s += 'L';
		}
		cout << s.size() << endl << s << endl;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值