We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Combinatorics
  4. Coinage

Coinage

Problem
Submissions
Leaderboard
Discussions
Editorial

The Indian bank issues coins in 4 denominations, ₹1, ₹2, ₹5 and ₹10.

Given a limited supply of each of the above denominations, in how many ways can you sum them up to a total of ₹N?

Input Format
The first line contains an integer T (number of testcases). Each testcase contains 2 lines. The first line contains integer N (sum to be achieved)
A, B, C and D in the next line, each representing the number of ₹1, ₹2, ₹5 and ₹10 coins respectively.

Output Format
Output the number of ways in which we can achieve the sum N.

Constraints
1 <= T <= 150
1 <= N <= 1000
1 <= A <= 10000
1 <= B,C,D <= 1000

Sample Input

2
15
2 3 1 1
12
2 2 1 1

Sample Output

2
2

Explanation
In the first case we need to find the different ways to total to 15. We can use one ₹10 coin and one ₹5 coin or one ₹10 coin two ₹2 coin and one ₹1 coin. Proceed similarly for the second case.

Author

shashank21j

Difficulty

Medium

Max Score

40

Submitted By

2462

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website