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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back
#define md ((st + nd) >> 1)
#define lc (1 + (idx << 1))
#define rc (2 + (idx << 1))
const int N = 200005;
int a[N], b[N], c[N], d[N], lst1[N], lst2[N], lst3[N];

int main() {
	int n, k1, k2, k3;
	scanf("%d %d %d %d", &n, &k1, &k2, &k3);
	int res = 0, f;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i] % 4;
		c[i] = a[i] % 5;
		d[i] = a[i] % 8;
		if (abs(b[i] - b[i-1]) > k1) {
			lst1[i] = i - 1;
		} else {
			lst1[i] = lst1[i-1];
		}
		if (abs(c[i] - c[i-1]) > k2) {
			lst2[i] = i - 1;
		} else {
			lst2[i] = lst2[i-1];
		}
		if (abs(d[i] - d[i-1]) > k3) {
			lst3[i] = i - 1;
		} else {
			lst3[i] = lst3[i-1];
		}
		int mx = max(lst1[i], max(lst2[i], lst3[i]));
		if (i - mx > res) {
			res = i - mx;
			f = mx + 1;
		}
		res = max(res, i - mx);
	}
	printf("%d %d", f, f + res - 1);
	return 0;
}
Copy
Band Song 1 aboAdnan
GNU G++17
60 ms
6.0 MB
Accepted