Advertisement
Saleh127

CF 1157C1

Oct 8th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. ll a[200005],c,d,e,f,i,j,k,l;
  11.  
  12. cin>>c;
  13. string x;
  14. for(i=0;i<c;i++)
  15. {
  16. cin>>a[i];
  17. }
  18. k=min(a[0],a[c-1]);
  19. i=0;
  20. j=c-1;
  21.  
  22. for(l=1;l<=c;l++)
  23. {
  24. if(a[i]>=k && a[j]>=k)
  25. {
  26. k=min(a[i],a[j]);
  27. if(k==a[i])
  28. {
  29. x+='L';
  30. i++;
  31. }
  32. else
  33. {
  34. x+='R';
  35. j--;
  36. }
  37. }
  38. else if(a[i]>=k)
  39. {
  40. k=a[i];
  41. x+='L';
  42. i++;
  43. }
  44. else if(a[j]>=k)
  45. {
  46. k=a[j];
  47. x+='R';
  48. j--;
  49. }
  50. }
  51. cout<<x.size()<<endl<<x<<endl;
  52. return 0;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement