Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created July 11, 2019 08:56
Show Gist options
  • Save surinoel/80fdc635f2e1681f48e4450e3c1e94c8 to your computer and use it in GitHub Desktop.
Save surinoel/80fdc635f2e1681f48e4450e3c1e94c8 to your computer and use it in GitHub Desktop.
#include <deque>
#include <vector>
#include <iostream>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, L;
cin >> n >> L;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
deque<pair<int, int>> dq;
for (int i = 0; i < n; i++) {
if (dq.size() > 0 && i - dq[0].first > L - 1) {
dq.pop_front();
}
for (int j = dq.size() - 1; j >= 0; j--) {
if (dq[j].second < a[i]) {
break;
}
dq.pop_back();
}
dq.push_back(make_pair(i, a[i]));
cout << dq[0].second << ' ';
}
cout << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment