Timer is Running

Distributing Balls
Submissions: 654   Accuracy:


  Difficulty: Medium   Marks: 4

John is a very calm person. He loves children very much. As his birthday is coming, he decided to give some gifts to the poor children and wants to make them happy by giving them the balls. But his enemy does not like his idea and therefore he wants to destroy John's Plan. So, his enemy takes away the balls as much as he can in the absence of John. John becomes very sad and thinks how he would distribute the remaining balls so that all the children feel happy. Therefore our task is to find the number of ways of distributing the balls. If he can distribute it, output number of ways else print "-1" without quotes.

First line of the input contains an integer T, denoting number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case consists of three integers m, n and p denoting total number of balls, number of children and the balls enemy has taken respectively. The second line of each test case consists of n space separated integers denoting minimum number of balls needed by a child numbered i, where 1<= i <= n.

If he can distribute, print the number of ways mod 109+7, else print "-1" without quotes. 

1 <= T <= 100
1 <= m <= 1000
2 <= n <= 100
1 <= p <= 1000

13 4 5                        
2 3 1 3
30 10 14
2 2 1 1 1 2 2 3 1 1


** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Vaibhav Garg
Author: AdityaChatterjee

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.