Source Code
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <math.h>

#define pairi pair <int,int>
#define pairll pair <long long,long long>
#define vi vector <int> 
#define vll vector <long long> 
#define mapi map <int,int> 
#define mapill map <int,long long> 
#define seti set <int> 
#define setll set <long long> 
#define pb push_back
#define fr(i,a,b) for(int i = a ; i < b ; i++)
#define fir(i,a,b) for(int i = b ; i >= a ; i--)
typedef long long ll ;


using namespace std;

int main()
{
    int t , n , j , i , k , *a , k1 , k2 , k3 ;
    t = 1 ;
    while(t--)
    {
        cin >> n ;
        cin >> k1 >> k2 >> k3 ;
        a = new int[n] ;
        fr(i,0,n)
            cin >> a[i] ;
        int l = 1 , f = 1 , max_len = 1 ;
        j = 0 ;
        i = 0 ;
        while(i < n - 1)
        {
            int x = a[i+1] ;
            int y = a[i] ;
            if(abs(x%4 - y%4) <= k1 && abs(x%5 - y%5) <= k2 && abs(x%8 - y%8) <= k3)
                i++ ;
            else
            {
                if(i-j+1>max_len)
                {
                    max_len  = i-j+1 ;
                    l = j + 1 ;
                    f = i + 1 ;
                }
                j = i + 1 ;
                i = j ;
            }
        }
        if(i-j+1>max_len)
        {
                    max_len  = i-j+1 ;
                    l = j + 1 ;
                    f = i + 1 ;
        }
        cout << l << " " << f << endl ;
    }
}
Copy
Band Song 1 Mahmoud
GNU G++17
63 ms
1.4 MB
Accepted