Here is my problem: Given a set of arrays of size N and an integer K, you have to find the maximum integer for each and every contiguous subarray of size K for each of the given arrays. example: Sample Input
5 2
3 4 6 3 4
Sample Output
4 6 6 4
Here is my code.please help me.code is right but whenever I submit it,it shows me time limit exceed.
#include<bits/stdc++.h>
    #include<deque>
    #include<algorithm>
    using namespace std;
    int print(deque<int>arr,int n,int k)
    {
        int i,j,max;
        for(i=0;i<=n-k;i++)
        {
            max=arr[i];
            for(j=1;j<k;j++)
            {
                if(arr[i+j]>max)
                max=arr[i+j];
            }
                printf("%d ",max);
        }
        return 0;
    }
    int main()
    {
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL); 
        int t,n,k;
        cin>>t;
        while(t--)
        {
            cin>>n>>k;
            deque<int>arr;
            for(int i=0;i<n;++i)
            {
                int value;
                scanf("%d",&value);
                arr.push_back(value);
            }
            print(arr,n,k);
            printf("\n");
        }
        return 0;
    }
 
    