Similar Arrays

3

2 votes
Problem

Supoose a secret array A of N integers. You have to output the number of arrays which are similar to array A.

An array B is said to be similar to array A if -

1. The length of the array B is same as that of A i.e. equal to N.

2. Each element of the array B lies between [ lowerBound, upperBound ].

3. Difference between each pair of consecutive elements of array B should be equal to the difference between respective pair of consecutive elements in array A. So, (B[i-1]-B[i]) should be equal to (A[i-1]-A[i]) for all i from 1 to N-1.

You are given value of lowerBound and upperBound. You don't know the array A but you know an array C of N-1 elements which contain differences between each pair of consecutive integers of the array A. Output the number of arrays which are similar to the array A.

Constraints:

2 <= N <= 105

-2*109 <= C[i] <= 2*109

-109 <= lowerBound <= upperBound <= 109

Input Format:

The first line of input consists of one integer N.

Second line contains N-1 space separated integers representing the array C.

Third line contains 2 space separated integers representing values of lowerBound and upperBound respectively.

Output Format:

Output a single value equal to the number of similar arrays to array A.

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?