Source Code
#include <bits/stdc++.h>
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
	quick
	
    int n,k1,k2,k3;
	cin>>n>>k1>>k2>>k3;
	int a[n+1],b[n+1],c[n+1];
	int A[n+1],B[n+1],C[n+1];
	int Aa[n+1],Bb[n+1],Cc[n+1];
	for(int i=1;i<=n;i++)
    {
        cin>>Aa[i];
        Bb[i]=Aa[i]%5;
        Cc[i]=Aa[i]%8;
        Aa[i]%=4;
    }
    A[1]=B[1]=C[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(abs(Aa[i]-Aa[i-1])<=k1)
        {
            A[i]=A[i-1];
        }
        else A[i]=i;
        if(abs(Bb[i]-Bb[i-1])<=k2)
        {
            B[i]=B[i-1];
        }
        else B[i]=i;
        if(abs(Cc[i]-Cc[i-1])<=k3)
        {
            C[i]=C[i-1];
        }
        else C[i]=i;
    }

    a[n]=b[n]=c[n]=n;
    for(int i=n-1;i>=1;i--)
    {
        if(abs(Aa[i]-Aa[i+1])<=k1)
        {
            a[i]=a[i+1];
        }
        else a[i]=i;
        if(abs(Bb[i]-Bb[i+1])<=k2)
        {
            b[i]=b[i+1];
        }
        else b[i]=i;
        if(abs(Cc[i]-Cc[i+1])<=k3)
        {
            c[i]=c[i+1];
        }
        else c[i]=i;
    }
    int x=1,y=1,u,v;
    for(int i=1;i<=n;i++)
    {
        u=max(max(A[i],B[i]),C[i]);
        v=min(min(a[i],b[i]),c[i]);
        if(v-u>y-x) x=u,y=v;
    }
    cout<<x<<' '<<y<<endl;
	return 0;
}
Copy
Band Song 1 aboulkacem
GNU G++17
16 ms
7.4 MB
Accepted