Help me in solving STRSUB problem

My issue

what is the problem here in this code
after investing few hours, i still can’t get to the cause of failure

package alg;

import java.util.Scanner;

class Codechef {

static Scanner scanner = new Scanner(System.in);

public static void main(String args[]) {
	int T = scanner.nextInt();
	while (T-- != 0) {
		int N, K, Q;
		N = scanner.nextInt();
		K = scanner.nextInt();
		Q = scanner.nextInt();
		String s = scanner.next();
		while (Q-- != 0) {
			int L, R;
			L = scanner.nextInt();
			R = scanner.nextInt();
			int result = 0;
			for (int i = L; i <= R; i++) {
				for (int j = L; j <= R; j++) {
					int lower = j;
					int higher = j + i - 1;
					int count1 = 0;
					int count0 = 0;
					for (int k = lower; k <= higher; k++) {
						if (k >= s.length()) {
							break;
						}
						if (s.charAt(k) == '1') {
							count1++;
						} else {
							count0++;
						}
					}
					if (count1 <= K && count0 <= K) {
						result++;
					}
				}
			}
			System.out.println(result);
		}
	}
}

}

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	return 0;
}

Problem Link: Count Substrings Practice Coding Problem - CodeChef