fork(1) download
  1. #include <iostream>
  2. #include <deque>
  3. using namespace std;
  4.  
  5. int main() {
  6. ios_base::sync_with_stdio(false);
  7. cin.tie(0);
  8. int n, t, temp;
  9. cin >> n >> t;
  10. deque<pair<int, int>> dq;
  11.  
  12. for(int i = 0; i < n; i++) {
  13. cin >> temp;
  14. while(!dq.empty() && dq.back().second > temp)
  15. dq.pop_back();
  16. dq.push_back(make_pair(i, temp));
  17.  
  18. if(i >= t-1) {
  19. if(dq.front().second < dq.back().second)
  20. cout << dq.front().second << ' ';
  21. else
  22. cout << dq.back().second << ' ';
  23. if (dq.front().first == i)
  24. dq.pop_front();
  25. }
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 4180KB
stdin
7 3
1 3 2 4 5 3 1
stdout
1 1 1 1 1