ARRAYSUB

ARRAYSUB

#include<iostream>
#include<vector>
using namespace std;

int main()
{
 int t;
 cin>>t;
 int n;
 vector<int> arr(t);
 for(int i=0;i<t;i++)
 {
        cin>>arr[i];       
 }  
    cin>>n;
    int maxind,max=0;
 for(int i=0;i<t;i++)
 {
         if(i<n)
         {
                    if(arr[i]>max){max=arr[i];maxind=i;} 
         }
         else
         {
             cout<<max<<" ";
             if(arr[i]>max){max=arr[i];maxind=i;}
             else if(maxind==(i-n))
             {
          int mm = maxind;
                  max=arr[maxind+1];
                  for(int j=maxind+1;j<t;j++)
                        {
                         if(j<=(mm+n))
                             {if(arr[j]>max){max=arr[j];maxind=j;}}
                         else
                             break;                      
                        }        
             }  
           
         }


 }
 cout<<max<<endl;
//system("pause");
 return 0;
}

No comments:

Post a Comment