I was trying to solve this question https://www.spoj.com/problems/ARRAYSUB/

using sliding window technique.

I am getting wrong answer on test case 5

please help me correct the code.

#include <bits/stdc++.h>

using namespace std;

int main()

{

ios_base::sync_with_stdio(false);

cin.tie(NULL);cout.tie(NULL);

```
long long int n,k;
cin>>n;
long long int a[n],i,m=-1,j=0;
map<long long int,long long int> mp;
for(i=0;i<n;++i)
{ cin>>a[i];
}
cin>>k;
for(i=0;i<k;++i)
{
m=max(m,a[i]);
mp[a[i]]++;
}
cout<<m<<" ";
for(i=k;i<n;++i)
{
mp[a[j]]--;
if(mp[a[j]]==0)
mp.erase(mp[a[j]]);
mp[a[i]]++;
auto it=mp.end();
--it;
cout<<it->first<<" ";
j++;
}
return 0;
```

}