1157C1. Increasing Subsequence (easy version)

The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).

You are given a sequence ? consisting of ? integers. All these integers are distinct, each value from 1 to ? appears in the sequence exactly once.

You are making a sequence of moves. During each move you must take either the leftmost element of the sequence or the rightmost element of the sequence, write it down and remove it from the sequence. Your task is to write down a strictly increasing sequence, and among all such sequences you should take the longest (the length of the sequence is the number of elements in it).

For example, for the sequence [2,1,5,4,3] the answer is 4 (you take 2 and the sequence becomes [1,5,4,3], then you take the rightmost element 3 and the sequence becomes [1,5,4], then you take 4 and the sequence becomes [1,5] and then you take 5 and the sequence becomes [1], the obtained increasing sequence is [2,3,4,5]).

Input
The first line of the input contains one integer ? (1≤?≤2⋅105) — the number of elements in ?.

The second line of the input contains ? integers ?1,?2,…,?? (1≤??≤?), where ?? is the ?-th element of ?. All these integers are pairwise distinct.

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

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

Examples

input
5
2 1 5 4 3
output
4
LRRR
input
7
1 3 5 6 7 4 2
output
7
LRLRLLL
input
3
1 2 3
output
3
LLL
input
4
1 2 4 3
output
4
LLRL


Note
The first example is described in the problem statement.

题意:判断一个递增的串,不一定是加1

思路:每次找一个两边最小的,每次往里走,直到走不通。注意走到最中间的时候(l==r)

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int M=2e5+10;
const int MAX=1e18+10;
const double PI = acos(-1);
int a[M];
char s[M];
int main()
{
    int n,i,j,ans=0,p,q,e=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    int l=0,r=n-1;
    p=0;
    while(1)
    {
        if(l>r)
            break;
        if(l==r&&a[l]>p)
        {
            ans++;
            s[e++]='L';
        }
        if(a[l]<a[r])
        {
            if(a[l]>p)
            {
               ans++;
               s[e++]='L';
               p=a[l];
               l++;
            }
            else
            if(a[r]>p)
            {
                ans++;
                s[e++]='R';
                p=a[r];
                r--;
            }
            else
                break;

        }
        else
        if(a[r]<a[l])
        {
            if(a[r]>p)
            {
                ans++;
                s[e++]='R';
                p=a[r];
                r--;
            }
            else
            if(a[l]>p)
            {
                ans++;
               s[e++]='L';
               p=a[l];
               l++;
            }
            else
                break;

        }
        else
            break;
    }
    printf("%d\n%s\n",ans,s);
    return 0;
}

//100
//2 3 4 6 7 8 9 12 13 14 15 16 17 19 20 21 24 25 27 28 31 32 34 40 42 43 45 46 47 49 54 55 58 59 60 61 62 63 68 71 74 75 80 81 82 85 86 87 88 89 91 92 95 96 98 99 100 97 94 93 90 84 83 79 78 77 76 73 72 70 69 67 66 65 64 57 56 53 52 51 50 48 44 41 39 38 37 36 35 33 30 29 26 23 22 18 11 10 5 1

 

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可私 6信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可 6私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可私 6信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值