Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- int main(int argc, char const *argv[])
- {
- #ifndef ONLINE_JUDGE
- freopen("in.txt", "r", stdin);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- deque<int> deq;
- stack<int> st;
- st.push(0);
- string ans;
- int cnt = 0;
- int n, x;
- cin >> n;
- while (n--) {
- cin >> x;
- deq.push_back(x);
- }
- while (!deq.empty()) {
- if (st.top() >= deq.front() && st.top() >= deq.back())
- break;
- ++cnt;
- if (deq.front() < deq.back() && deq.front() > st.top()) {
- st.push(deq.front());
- ans += "L";
- deq.pop_front();
- }
- else {
- st.push(deq.back());
- ans += "R";
- deq.pop_back();
- }
- }
- cout << cnt << '\n' << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement