|
| 1 | +# Customers in Strangeland are strange. A customer points at some kind of sweets and gives several banknotes |
| 2 | +# to the seller. This means that he wants to buy a positive number of sweets of that kind. He doesn't tell |
| 3 | +# the exact number of sweets he wants to buy. The only thing Ann knows is: an 'adequate' customer won't give |
| 4 | +# any extra banknotes. It means that if you throw away any banknote, the resulting amount of money won't be |
| 5 | +# enough to buy the wanted number of sweets. |
| 6 | +# |
| 7 | +# Ann has to determine the number of sweets the customer wants. Help Ann write a program which determines |
| 8 | +# this number or tells that it's impossible. |
| 9 | +# |
| 10 | +# Input |
| 11 | +# The first line of the input contains a single integer T, the number of test cases (no more than 20). |
| 12 | +# T test cases follow. Each test case consists of two lines. The first of these lines contains two integers |
| 13 | +# N and X (1 ≤ N, X ≤ 100) separated by a single space. N is the number of banknotes given by the customer. |
| 14 | +# X is the cost of a single sweet of the chosen kind. The second of these lines contains N space-separated |
| 15 | +# integers Ai (1 ≤ Ai ≤ 100), the values of the banknotes. |
| 16 | +# |
| 17 | +# Output |
| 18 | +# For each test case output exactly one line containing a single integer: |
| 19 | +# |
| 20 | +# -1 if the customer is inadequate and has given extra banknotes, or |
| 21 | +# K, the number of sweets the customer wants to buy. If there are several possible answers, output the |
| 22 | +# largest of them. |
| 23 | +# |
| 24 | +# Example |
| 25 | +# Input: |
| 26 | +# 3 |
| 27 | +# 4 7 |
| 28 | +# 10 4 8 5 |
| 29 | +# 1 10 |
| 30 | +# 12 |
| 31 | +# 2 10 |
| 32 | +# 20 50 |
| 33 | +# |
| 34 | +# Output: |
| 35 | +# -1 |
| 36 | +# 1 |
| 37 | +# 7 |
| 38 | +# |
| 39 | +# Explanation |
| 40 | +# In the first test case, the total amount of money received from the customer is 27. He can't buy more than |
| 41 | +# 3 sweets with this amount. If you throw away the banknote of value 5 (or of value 4), it will still be |
| 42 | +# possible to buy 3 sweets. Hence the customer is inadequate. |
| 43 | +# |
| 44 | +# In the second test case, it's clear that he wants to buy just one sweet (note that this number should be |
| 45 | +# positive). |
| 46 | +# |
| 47 | +# In the third test case, the total amount of money received is 70, which is enough for 7 sweets. The |
| 48 | +# customer might want to buy only 6 sweets, but we are interested in the largest possible answer. |
| 49 | +testCases = int(input()) |
| 50 | +while testCases: |
| 51 | + testCases -= 1 |
| 52 | + N, X = map(int, input().split()) |
| 53 | + bankNotes = [int(i) for i in input().split()] |
| 54 | + bankNotes = sum(bankNotes) |
| 55 | + if (N * X) <= bankNotes: |
| 56 | + result = bankNotes // X |
| 57 | + print(int(result)) |
| 58 | + else: |
| 59 | + print(int('-1')) |
0 commit comments