Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- bool compare(string a, string b) {
- return a.size() < b.size();
- }
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int n;
- cin >> n;
- deque<int>d(n);
- for (int i=0; i<n; i++) {
- cin >> d[i];
- }
- vector<int>onTable;
- // int mx=0;
- int q;
- cin >> q;
- while (q--) {
- char x; cin >> x;
- if (x=='L') {
- if (!d.empty()) {
- // mx=max(mx,d.front());
- onTable.push_back(d.front());
- d.pop_front();
- }
- }
- else if (x=='R') {
- if (!d.empty()) {
- // mx=max(mx,d.back());
- onTable.push_back(d.back());
- d.pop_back();
- }
- }
- else {
- if (!onTable.empty()) {
- sort(onTable.begin(), onTable.end());
- cout << onTable.back() << endl;
- onTable.pop_back();
- }
- else cout << -1 << endl;
- // cout << mx << endl;
- }
- }
- return 0;
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment