Source Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lp(j,n) for(int i=j;i<n;i++)
#define nlp(x,y,n) for(int i=x;i<n;i++)for(int j=y;j<n;j++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int fac(int x)
{
    if(x>1)
        return x*fac(x-1);
    return 1;
}
bool is_prime(int x)
{
   if(x==1)
    return false;

   for(int i=2;i<=sqrt(x);i++)
      if(x%i==0)
        return false;

    return true;
}
int main()
{
	fast

	int n,k1,k2,k3,arr[200006],h[2000006],ri[2000006],ra[2000006];

	cin>>n>>k1>>k2>>k3;

	lp(1,n)
	{
	    cin>>arr[i];
	    
	    h[i]=arr[i]%4;
	    ri[i]=arr[i]%5;
	    ra[i]=arr[i]%8;
	}

	int start = 0,endd = 0;
	
	for(int i=1;i<n;i++)
    {
        int tmp_start=0,tmp_end=0;
        
        if(abs(h[i]-h[i+1])<=k1 && abs(ri[i]-ri[i+1])<=k2 && abs(ra[i]-ra[i+1])<=k3)
        {
            tmp_start = i;
            
            i++;
            
            while(i<n)
            {
                if(abs(h[i]-h[i+1])<=k1 && abs(ri[i]-ri[i+1])<=k2 && abs(ra[i]-ra[i+1])<=k3)
                    tmp_end = i+1;
                else
                    break;
                i++;
            }
        }
        
        if(tmp_end-tmp_start+1>endd-start+1)
        {
            start = tmp_start;
            endd = tmp_end;
        }
    }
	cout<<start<<" "<<endd;
}
/*

*/
Copy
Band Song 1 karim
GNU G++17
48 ms
25.2 MB
Accepted