self created question

Given a binary array (consisting of 0's and 1's only) A of size N and 2 integers X and Y. Find the number of non-empty contiguous subsequences which have the count of 0's greater than X and the count of 1's greater than Y.
Input The first line of input contains a single integer N denoting the number of elements of array A. The second line of input contains N space separated integers A1,A2,....,AN denoting the elements of array A. This is followed by a line containing 2 space separated integers X and Y as described in the problem statement.
Output The output should consist of a single integer denoting the answer to the problem.
Constraints 1 ≤ N ≤ 105 0 ≤ X,Y < N 0 ≤ Ai ≤ 1
I
Input: 4 1 0 0 1 1 1 Output: 1
Input: 6 1 1 0 0 1 0 1 1 Output: 5
Explanation Example case 1. The only subarray with the number of 0's greater than 1 and the number of 1's greater than 1 is the one indexed from 1 to 4, hence the answer is 1.
Example case 2. The subarrays that have number of 0's greater than 1 and the number of 1's greater than 1 are [1,4], [1,5], [1,6], [2,5] and [2,6], hence the answer is 5. Here [i,j] is the subarray indexed from i to j.

Comments (0)