Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. int main(int argc, char const *argv[])
  6. {
  7. #ifndef ONLINE_JUDGE
  8. freopen("in.txt", "r", stdin);
  9. #endif
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(0);
  12.  
  13. deque<int> deq;
  14. stack<int> st;
  15. st.push(0);
  16. string ans;
  17. int cnt = 0;
  18.  
  19. int n, x;
  20. cin >> n;
  21. while (n--) {
  22. cin >> x;
  23. deq.push_back(x);
  24. }
  25.  
  26. while (!deq.empty()) {
  27. if (st.top() >= deq.front() && st.top() >= deq.back())
  28. break;
  29. ++cnt;
  30. if (deq.front() < deq.back() && deq.front() > st.top()) {
  31. st.push(deq.front());
  32. ans += "L";
  33. deq.pop_front();
  34. }
  35. else {
  36. st.push(deq.back());
  37. ans += "R";
  38. deq.pop_back();
  39. }
  40.  
  41. }
  42. cout << cnt << '\n' << ans << '\n';
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement