Source Code
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, k1, k2, k3;
    cin >> n >> k1 >> k2 >> k3;
    int arr1[n], arr2[n], arr3[n];
    for(int i = 0; i < n; i++){
        cin >> arr1[i];
        arr2[i] = arr1[i] % 5;
        arr3[i] = arr1[i] % 8;
        arr1[i] %= 4;
    }
    int mxL = 1, mxR = 1;
    for(int i = 0; i < n; i++){
        int l = i;
        i++;
        while(i < n && abs(arr1[i] - arr1[i - 1]) <= k1 && abs(arr2[i] - arr2[i - 1]) <= k2 && abs(arr3[i] - arr3[i - 1]) <= k3){
            i++;
        }
        i--;
        int r = i;
        if(r - l + 1 > mxR - mxL + 1){
            mxR = r + 1;
            mxL = l + 1;
        }
    }

    cout << mxL << " " << mxR << endl;
	return 0;
}
Copy
Band Song 1 Mohamedmaher
GNU G++17
70 ms
2.9 MB
Accepted