Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- deque<int> d;
- for (int i = 0; i < n; ++i) {
- while (!d.empty() && a[d.back()] >= a[i]) {
- d.pop_back();
- }
- d.push_back(i);
- while (d.front() <= i - k) {
- d.pop_front();
- }
- if (i >= k - 1) {
- cout << a[d.front()] << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement