What’s wrong with this code?
#include
#include
#include
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
int a[100000];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
deque Q(k);
int i;
for(i=0;i<k;i++)
{
while(!Q.empty() && a[i]>a[Q.back()]){
Q.pop_back();
}
Q.push_back(i);
}
for(;i<n;i++)
{
cout<<a[Q.front()]<<" ";
while((!Q.empty() && (Q.front() <= i-k))){
Q.pop_front();
}
while(!Q.empty() && a[i]>=a[Q.back()]){
Q.pop_back();
}
Q.push_back(i);
}
return 0;
}