lina_os

Untitled

Mar 21st, 2025
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. bool compare(string a, string b) {
  7. return a.size() < b.size();
  8. }
  9.  
  10. int main() {
  11. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  12. int n;
  13. cin >> n;
  14. deque<int>d(n);
  15. for (int i=0; i<n; i++) {
  16. cin >> d[i];
  17. }
  18. vector<int>onTable;
  19. // int mx=0;
  20. int q;
  21. cin >> q;
  22. while (q--) {
  23. char x; cin >> x;
  24. if (x=='L') {
  25. if (!d.empty()) {
  26. // mx=max(mx,d.front());
  27. onTable.push_back(d.front());
  28. d.pop_front();
  29. }
  30. }
  31. else if (x=='R') {
  32. if (!d.empty()) {
  33. // mx=max(mx,d.back());
  34. onTable.push_back(d.back());
  35. d.pop_back();
  36. }
  37. }
  38. else {
  39. if (!onTable.empty()) {
  40. sort(onTable.begin(), onTable.end());
  41. cout << onTable.back() << endl;
  42. onTable.pop_back();
  43. }
  44. else cout << -1 << endl;
  45. // cout << mx << endl;
  46. }
  47. }
  48. return 0;
  49. }
  50.  
  51. /*
  52. */
Advertisement
Add Comment
Please, Sign In to add comment