Source Code
#include <bits/stdc++.h>
using namespace std;
const int N = 500001;  
int v[N] ; 
int n , k1 , k2 , k3 ; 

bool valid(int x1, int x2, int x3) {
		if (x1<=k1 && x2 <= k2 && x3 <= k3 )
			return true; 
		return false ; 
} 

int main() {
	vector<int>a, b , c;  

	cin>>n>>k1>>k2>>k3; 
	for (int i =0 ; i<n ; ++i) {
		cin>>v[i] ; 

		a.push_back(v[i]%4) ; 
		b.push_back(v[i]%5) ; 
		c.push_back(v[i]%8) ; 
	}
	
	int l = 0 , r = 0 , idx1 = 0 , idx2 = 0 , mx = 0 , ans1 = 0 , ans2 = 0 ; 
	while (l<n && r<n) {
		if (r == n-1)
			break ; 
		while (r<n-1) {
			idx1 = l ; 
			idx2 = l ; 
			int x1 = abs(a[r]-a[r+1]) ; 
			int x2 = abs(b[r]-b[r+1]) ; 
			int x3 = abs(c[r]-c[r+1]) ;
				r++;
			if (valid(x1, x2, x3)){
			
				idx2 = r; 
					if(mx < r-l) {
						mx = r-l;
						ans1 = idx1 ; 
						ans2 = idx2 ; 
					}
			}else {
			
				l = r ; 
				break ; 
			}
		}
	}
	cout<<ans1+1<<" "<<ans2+1<<endl;
	return 0;
}
Copy
Band Song 1 Chicou
GNU G++17
52 ms
3.5 MB
Accepted