Partitions

3.9

13 votes
Algorithms, Binary Search, Medium, Searching, partitions
Problem

You are given an array a of size n and two integers l and r. You have to find the number of partitions of array a such that the sum of elements in each partition lies between l and r(both inclusive). Since the answer can be large, find the answer modulo 109+7 (1000000007).

Input Format

First line contains 3 space separated denoting the values of n, l and r (1n105, 1lr1012).

Next line contains n space separated integers denoting the values of array a (1a[i]r).

Output Format

Print the answer in a single line.

Sample Input
5 3 12
3 5 1 2 6
Sample Output
8
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

There are 8 partitions such that sum of elements in each partition lies between given l and r.

Editor Image

?