fork download
  1. /*
  2.  
  3.   F U Z U M I T A K A H A S H I -w-
  4.  
  5. */
  6. #include <bits/stdc++.h>
  7.  
  8. using namespace std;
  9.  
  10. int n, m;
  11. deque<int> q;
  12.  
  13. signed main(){
  14. cin >>n >>m;
  15. int a[n + 1];
  16. for (int i = 1; i <= n; ++i){
  17. cin >>a[i];
  18. while (!q.empty() && a[i] <= a[q.back()]) q.pop_back();
  19. q.push_back(i);
  20. if (q.front() + m <= i) q.pop_front();
  21. if (i >= m) cout <<a[q.front()] <<' ';
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5260KB
stdin
10 6
16 61 18 55 68 60 57 43 10 37 
stdout
16 18 18 10 10