Advertisement
TAHMID37

C codeforce

Jul 5th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. /*  TAHMID RAHMAN
  2.     DAMIAN FOREVER
  3.      MATH LOVER
  4.     NEVER GIVE UP
  5. */
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. #define pi acos(-1.0)
  9. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  10. #define ll long long
  11. #define pb push_back
  12. #define fi first
  13. #define se second
  14. #define in insert
  15. #define mp make_pair
  16. #define GCD(a,b) __gcd(a,b);
  17. #define endl "\n"
  18. #define FRU freopen("out.txt","w",stdout)
  19. #define FRO freopen("in.txt","r",stdin)
  20. #define INFLL 9223372036854775807
  21. #define debug 0
  22. #define MAXN   100001
  23. #define ar array
  24. const int mxN=2e5;
  25. const int MOD=1e9+7;
  26. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
  27. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  28. int main()
  29. {
  30.     fastio;
  31.     char s='L',t='R';
  32.     ll n,i;
  33.     cin>>n;
  34.     vector<ll>v(n);
  35.     vector<char>co;
  36.     for(i=0;i<n;i++)
  37.         cin>>v[i];
  38.     ll l=0,h=n-1;
  39.     ll cur=0;
  40.     if(v[l]<v[h])
  41.     {
  42.         cur=v[l];
  43.         l++;
  44.         co.pb(s);
  45.     }
  46.     else
  47.     {
  48.         cur=v[h];
  49.         h--;
  50.         co.pb(t);
  51.     }
  52.     while(l<=h)
  53.     {
  54.  
  55.         if(cur>v[l]&&cur>v[h])
  56.             break;
  57.         else if(cur<v[l]&&v[h]<cur)
  58.         {
  59.             co.pb(s);
  60.             l++;
  61.             cur=v[l];
  62.         }
  63.         else if(cur<v[h]&&v[l]<cur)
  64.         {
  65.             co.pb(t);
  66.             h--;
  67.             cur=v[h];
  68.         }
  69.         else if(v[l]>cur&&v[h]>cur)
  70.         {
  71.             if(v[l]>v[h])
  72.             {
  73.                 cur=v[h];
  74.                 h--;
  75.                co.pb(t);
  76.             }
  77.             else
  78.             {
  79.                 cur=v[l];
  80.                 l++;
  81.                 co.pb(s);
  82.  
  83.             }
  84.         }
  85.         else if(l==h)
  86.         {
  87.             if(v[l]>cur)
  88.             {
  89.  
  90.                 co.pb(s);
  91.                 break;
  92.  
  93.             }
  94.             else
  95.                 break;
  96.  
  97.         }
  98.  
  99.     }
  100.     cout<<co.size()<<endl;
  101.     for(auto x:co)
  102.     {
  103.         cout<<x;
  104.     }
  105.     cout<<endl;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement