Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- #ifndef ONLINE_JUDGE
- freopen("seq_in.txt", "r", stdin);
- #endif
- int n;
- cin >> n;
- list<int> nums;
- for(int i = 0; i < n; ++i)
- {
- int k;
- cin >> k;
- nums.push_back(k);
- }
- string order;
- int prev;
- if (nums.front() < nums.back())
- {
- prev = nums.front();
- nums.pop_front();
- order = "L";
- }
- else
- {
- prev = nums.back();
- nums.pop_back();
- order = "R";
- }
- for(int i = 0; i < n - 1; ++i)
- {
- if ((nums.front() < nums.back() || prev > nums.back()) && prev < nums.front())
- {
- prev = nums.front();
- nums.pop_front();
- order += "L";
- }
- else if (prev < nums.back())
- {
- prev = nums.back();
- nums.pop_back();
- order += "R";
- }
- else break;
- }
- cout << order.length() << '\n' << order;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement