Codechef•May 25, 2025
Minimum number of coins
Hazrat Ali
Codechef
Find the minimum number of coins Chef needs, to pay exactly X rupees. If it is impossible to pay X rupees in denominations of rupees 5 and 10 only, print −1.
Input Format
- First line will contain TT, number of test cases. Then the test cases follow.
- Each test case contains of a single integer XX.
Output Format
For each test case, print a single integer - the minimum number of coins Chef needs, to pay exactly XX rupees. If it is impossible to pay XX rupees in denominations of rupees 5 and 10 only, print −1.
Constraints
- 1≤T≤1000
- 1≤X≤1000
Subtasks
- Subtask 1 (100 points): Original constraints.
Sample 1:
Input
3 50 15 8
Output
5 2 -1
Solution
for _ in range(int(input())):
n=int(input())
coin=int(n/10)
coin2=n-coin*10
coin3=int(coin2/5)
sol=n-coin3*5-coin*10
if sol>0:
print(-1)
else:
print(coin3+coin)