forked from OmkarPathak/Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP15_BUYING2.py
More file actions
56 lines (55 loc) · 2.2 KB
/
Copy pathP15_BUYING2.py
File metadata and controls
56 lines (55 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Banknotes in the state of Strangeland don't have any regulated values like 1, 5, 10, 20, 50, 100, etc. In fact, it's
# possible to see any positive integer on a banknote of Strangeland. Indeed, this isn't the most convenient thing.
#
# Ann is working as a sweet seller at a shop in Strangeland. Every kind of sweets in this shop has its own cost, and
# sweets of the same kind have the same cost.
#
# Customers in Strangeland are strange. A customer points at some kind of sweets and gives several banknotes to the
# seller. This means that he wants to buy a positive number of sweets of that kind. He doesn't tell the exact number of
# sweets he wants to buy. The only thing Ann knows is: an 'adequate' customer won't give any extra banknotes. It means that
# if you throw away any banknote, the resulting amount of money won't be enough to buy the wanted number of sweets.
#
# Ann has to determine the number of sweets the customer wants. Help Ann write a program which determines this number or
# tells that it's impossible.
#
# Input
# The first line of the input contains a single integer T, the number of test cases (no more than 20). T test cases follow.
# Each test case consists of two lines. The first of these lines contains two integers N and X (1 ≤ N, X ≤ 100) separated by
# a single space. N is the number of banknotes given by the customer. X is the cost of a single sweet of the chosen kind.
# The second of these lines contains N space-separated integers Ai (1 ≤ Ai ≤ 100), the values of the banknotes.
#
# Output
# For each test case output exactly one line containing a single integer:
#
# -1 if the customer is inadequate and has given extra banknotes, or
# K, the number of sweets the customer wants to buy. If there are several possible answers, output the largest of them.
#
# Example
#
# Input:
# 3
# 4 7
# 10 4 8 5
# 1 10
# 12
# 2 10
# 20 50
#
# Output:
# -1
# 1
# 7
testCases = int(input())
while testCases:
testCases -= 1
N, X = map(int, input().split())
bankNotes = [int(i) for i in input().split()]
bankNotes = sum(bankNotes)
if (X) <= bankNotes:
result = bankNotes // (X)
if result >= N:
print(result)
else:
print(-1)
else:
print(-1)