Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TAHMID RAHMAN
- DAMIAN FOREVER
- MATH LOVER
- NEVER GIVE UP
- */
- #include<bits/stdc++.h>
- using namespace std;
- #define pi acos(-1.0)
- #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- #define ll long long
- #define pb push_back
- #define fi first
- #define se second
- #define in insert
- #define mp make_pair
- #define GCD(a,b) __gcd(a,b);
- #define endl "\n"
- #define FRU freopen("out.txt","w",stdout)
- #define FRO freopen("in.txt","r",stdin)
- #define INFLL 9223372036854775807
- #define debug 0
- #define MAXN 100001
- #define ar array
- const int mxN=2e5;
- const int MOD=1e9+7;
- bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
- //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
- int main()
- {
- fastio;
- char s='L',t='R';
- ll n,i;
- cin>>n;
- vector<ll>v(n);
- vector<char>co;
- for(i=0;i<n;i++)
- cin>>v[i];
- ll l=0,h=n-1;
- ll cur=0;
- if(v[l]<v[h])
- {
- cur=v[l];
- l++;
- co.pb(s);
- }
- else
- {
- cur=v[h];
- h--;
- co.pb(t);
- }
- while(l<=h)
- {
- if(cur>v[l]&&cur>v[h])
- break;
- else if(cur<v[l]&&v[h]<cur)
- {
- co.pb(s);
- l++;
- cur=v[l];
- }
- else if(cur<v[h]&&v[l]<cur)
- {
- co.pb(t);
- h--;
- cur=v[h];
- }
- else if(v[l]>cur&&v[h]>cur)
- {
- if(v[l]>v[h])
- {
- cur=v[h];
- h--;
- co.pb(t);
- }
- else
- {
- cur=v[l];
- l++;
- co.pb(s);
- }
- }
- else if(l==h)
- {
- if(v[l]>cur)
- {
- co.pb(s);
- break;
- }
- else
- break;
- }
- }
- cout<<co.size()<<endl;
- for(auto x:co)
- {
- cout<<x;
- }
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement