fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define fr first
  4. #define sc second
  5. #define sz(x) (int) x.size()
  6. #define pb push_back
  7. #define all(x) x.begin(), x.end()
  8.  
  9. using namespace std;
  10. using pii = pair<ll, ll>;
  11. using tii = tuple<ll, ll, ll>;
  12. string printBin(ll m) { string a = ""; for(int i=63; i>=0; i--) { if(m & (1<<i)) {a += '1';} else {a += '0';} } return a; }
  13.  
  14. int main() {
  15. int n, k;
  16.  
  17. while(cin >> n >> k) {
  18. if(n == k && n == 0) break;
  19.  
  20. priority_queue<pii, vector<pii>, greater<>> disp;
  21.  
  22. int cont = 0;
  23. for(int i=1; i<=n; i++) {
  24. ll ai; cin >> ai;
  25. disp.push({ai, i});
  26.  
  27. if(i - k < 0) continue;
  28. while(sz(disp) > 0) {
  29. auto [aj, ij] = disp.top();
  30. if(ij > i - k) {
  31. if(cont > 0) cout << " ";
  32. cout << aj;
  33. cont++;
  34. break;
  35. }
  36. else disp.pop();
  37. }
  38. }
  39. cout << endl;
  40. }
  41.  
  42. }
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
Standard output is empty