nikhil-and-his-golden-children

Mr Nikhil has k Children. They are suffering from a disease called Gasomia . 
According to his family Doctor , Child 1 requires atleast x1 tablets , Child 2 requires atleast  x2 ......... Child k requires atleast xk tablets.
As Nikhil got job in Golden Ship,he bought m tablets and wants to distribute all the tablets among his children.Can you tell him the number of ways of distributing tablets among children in such a way,that all the children get satisfied.
As the numbers of ways can be very large, print ans mod 1000000007

Input
First line of the input contains T , denoting number of test cases

For each test case it  contains two integers k and m denoting— number of children and the number of tablets he have respectively.

Then follow k  numbers , denoting minimum tablets needed by child i, 1≤ i ≤ k

Output
Print the number of ways % 1000000007.

SAMPLE INPUT
1
2 3
1 1

SAMPLE OUTPUT
2

Explanation

In the Sample Test Case ,Nikhil has 2 children x1 and x2 and he bought 3 tablets.
x1 needs atleast 1 tablet
x2 needs atleast 1 tablet
so he can distribute in 2 ways i.e (1,2) and (2,1)

Source: hackerearth | Difficulty: EASY
Tags: Combinatorics


Solutions:
from sys import stdin

def main():
	nextint = iter(map(int, stdin.read().split())).__next__
	fact = [1]
	mod = 1000000007
	for x in range(1, 100001):
		fact.append((fact[-1] * x) % mod)
	for _ in range(nextint()):
		k, m = nextint(), nextint()
		n = m - sum([nextint() for _ in range(k)])
		if n < 0:
			print(0)
		else:
			# print n + k - 1, n,  k
			print((fact[n + k - 1] * pow(fact[k - 1] * fact[n], mod - 2, mod)) % mod)

main()


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
def f (n,r,m):
	fac=1
	rfac=1
	for i in range(1,r+1):
		fac=(fac*(n-r+i))
		rfac=rfac*i
	return (fac/rfac)%m
t=eval(input())
while t>0:
	t-=1
	n,m=list(map(int,input().split()))
	l=[int(i) for i in input().split()]
	s=m-sum(l)
	if s==0:
		print("1")
	else:
		if s<0:
			print("0")
		else:
			print(f(n+s-1,n-1,1000000007))