-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path64.cpp
More file actions
35 lines (32 loc) · 838 Bytes
/
64.cpp
File metadata and controls
35 lines (32 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
vector<int> maxInWindows(const vector<int> &num, unsigned int size) {
vector<int> v;
deque<int> d;
for (unsigned int i = 0; i < num.size(); ++i) {
while (d.size() && num[d.back()] <= num[i])
d.pop_back();
if (d.size() && i - d.front() + 1 > size)
d.pop_front();
d.push_back(i);
if (size && i + 1 >= size)
v.push_back(num[d.front()]);
}
return v;
}
int main() {
ios::sync_with_stdio(false);
vector<int> v, res;
int n, k, tmp;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> tmp;
v.push_back(tmp);
}
res = maxInWindows(v, k);
for (auto it = res.begin(); it != res.end(); ++it)
cout << *it << " ";
return 0;
}