fork download
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC optimize("unroll-loops")
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. // #define int long long
  6. #define fi first
  7. #define se second
  8. int32_t main()
  9. {
  10. ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
  11. int n,x;
  12. cin>>n>>x;
  13. int a[n+5];
  14. for(int i=1; i<=n; i+=1)
  15. {
  16. cin>>a[i];
  17. }
  18. int l=0, r=0;
  19. multiset<int>s;
  20. //s.insert(a[1]);
  21. stringstream output;
  22. while(r<n && l<n-x+1)
  23. {
  24. l++;
  25. while(r-l<x-1)
  26. {
  27. r++;
  28. if(r<=n && r>=1)
  29. {
  30. s.insert(a[r]);
  31. }
  32. }
  33. if(s.size()>0)
  34. {
  35. auto it=s.begin();
  36. int med=(s.size()-1)>>1;
  37. for(int i=1; i<=med; i+=1)
  38. {
  39. it++;
  40. }
  41. cout<<*it<<' ';
  42. }
  43. if(s.find(a[l])!=s.end())
  44. {
  45. s.erase(s.find(a[l]));
  46. }
  47. }
  48. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty