Geeksforgeeks

Timer is Running

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.

**Input:**

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.

**Output:**

If he can distribute, print the number of ways **mod 10 ^{9}+7**, else print "

**Constraints:**

1 <= T <= 100

1 <= m <= 1000

2 <= n <= 100

1 <= p <= 1000

**Example:
Input **

2

13 4 5

2 3 1 3

30 10 14

2 2 1 1 1 2 2 3 1 1

**Output**

-1

1

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.

jainshubham52535 | 529 |

Pathak1899 | 436 |

yashdip123 | 380 |

kirtidee18 | 377 |

jots62 | 351 |

kirtidee18 | 1057 |

ykaushik | 752 |

aggarwalvatsal5 | 741 |

harbilassingh | 576 |

pmr_3689 | 570 |

blackshadows | 5456 |

Ibrahim Nash | 5450 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4827 |

Login to report an issue on this page.