SHARE
TWEET

Untitled

a guest Apr 26th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(NULL);
  10.  
  11. #ifndef ONLINE_JUDGE
  12.     freopen("seq_in.txt", "r", stdin);
  13. #endif
  14.  
  15.     int n;
  16.     cin >> n;
  17.  
  18.     list<int> nums;
  19.     for(int i = 0; i < n; ++i)
  20.     {
  21.         int k;
  22.         cin >> k;
  23.  
  24.         nums.push_back(k);
  25.     }
  26.  
  27.     string order;
  28.  
  29.     int prev;
  30.  
  31.     if (nums.front() < nums.back())
  32.     {
  33.         prev = nums.front();
  34.         nums.pop_front();
  35.         order = "L";
  36.     }
  37.     else
  38.     {
  39.         prev = nums.back();
  40.         nums.pop_back();
  41.         order = "R";
  42.     }
  43.    
  44.  
  45.     for(int i = 0; i < n - 1; ++i)
  46.     {
  47.         if ((nums.front() < nums.back() || prev > nums.back()) && prev < nums.front())
  48.         {
  49.             prev = nums.front();
  50.             nums.pop_front();
  51.             order += "L";
  52.         }
  53.         else if (prev < nums.back())
  54.         {
  55.             prev = nums.back();
  56.             nums.pop_back();
  57.             order += "R";
  58.         }
  59.         else break;
  60.     }
  61.    
  62.     cout << order.length() << '\n' << order;
  63.  
  64.     return 0;
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top