The Demonetization Dilemma
Tag(s):

## Algorithms, Dynamic Programming, Medium, Medium

Problem
Editorial
Analytics

Anik is big foodie and frequently goes on outings to restaurants and food corners in the city or town he is living in. Due to the Indian government’s decision to demonetize Rs 500 and Rs 1000, Anik is in a huge scarcity for change. He cannot possibly survive without his beloved food. Notes are not available in the market, so he is having to pay only through coins. So he decides that he will pay the amount through the minimum number of coins he possibly can.

Input:

First line contains a number T which denotes the number of test cases. Each test case contains 3 lines.

1. First line consists of a single integer A which signifies the amount Anik has to pay.
2. Second line consists of a single integer N which is the number of coin denominations available in the market.
3. Third line consists of N integers a1, a2, a3 ... an denoting the coin denominations available in the market.

Output:

Output should consist of a positive integer which signifies the minimum number of coins in which Anik can pay. If there exists no way in which Anik can pay, print No solution.

Constraints:

1 <= T <= 1000

0 <= A <= 10000

1 <= N <= 100

1 <= ai <= 1000

SAMPLE INPUT
1
4
2
1 2
SAMPLE OUTPUT
2
Explanation

Rs 4 can be paid through 2 coins of Rs 2.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic

## CODE EDITOR

Initializing Code Editor...