CT36494

Wistful stairwells Exact Tender

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The store warden Kate has been asked to audit the season's records. On the desk lies a long table of stairwells readings. Task: Coins of n given sizes may be used without limit. Print the minimum number of coins summing exactly to amount, or -1. Input format: First line: amount and n. Second line: n distinct coin sizes. Output format: Print the minimum coin count, or -1. Constraints: 0 <= amount <= 10000; 1 <= n <= 50; 1 <= coin <= 10^4.

Example 1:

Input: 6678 34 1 216 566 1226 1875 2540 2935 3460 3580 4075 4189 4234 4305 4310 4747 5647 6290 6695 6903 7050 7156 7176 7377 7397 7405 7468 7674 8647 8669 9190 9258 9405 9798 9869
Output: 6

Example 2:

Input: 8296 34 1 351 462 508 619 1109 1177 1234 1242 1399 1568 1721 2005 2376 2744 3297 3300 3851 3908 4072 4876 5014 6307 6625 7080 7461 7770 8582 8875 9332 9415 9900 9908 9986
Output: 4

Example 3:

Input: 5153 34 348 361 435 843 872 1458 1490 1527 2045 2643 2697 2938 3074 3489 4382 4563 4709 4731 4942 5040 5769 5946 6647 6800 6847 6921 7034 7619 7798 8021 8625 8791 9311 9369
Output: 5

Constraints:

0 <= amount <= 10000; 1 <= n <= 50; 1 <= coin <= 10^4.

Loading...
Test Cases:No test cases
No test cases available.