

‘N’ = 5, cost: {2, 3, 1, 2, 4, 1, 5, 77, 4}
For the given example, the largest possible value that can be formed is 66666. As the cost of each 5 is 1 and we have a total of 5 coins. Hence the answer is 66666.
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows:
The first line of each test case contains a single integer ‘N’ denoting the total number of coins Mikasa has.
The second line of the test case contains 9 integers denoting the cost of every number from 1 to 9.
For each test case, print a single integer denoting the largest possible number.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 1000
1 <= coins[i] <= 1000
Time limit: 1 sec
To do this, we will make another function ‘largetNumberHelper’ and we will pass an integer ‘N’ which represents the number of coins left after taking the ‘i’th number from 1 to 9 and the vector ‘cost’.
The steps are as follows:
In this approach, we will not only calculate the maximum possible number we can make with every cost from 1 to ‘N’ using the given cost but will also store them in an array ‘dp’. By doing so, we will be able to skip many precomputed cases, hence reducing the time complexity.
The steps are as follows:
‘largestNumberHelper(N, cost, dp)’:
In this approach, we will iterate through the arrays ‘coins’, and for each coin, we will calculate the maximum number possible which we can make from all the coins from 1 to 9 and if we found a coin having cost less than or equal to the current coins we are taking we will update the maximum of the two strings we have, i.e. the previous string ‘dp[j]’ and the new string which will be (char)(i + ‘0’) + ‘dp[j - cost[i]]’
The steps are as follows: