CT37964

The Teal runs of Brewer

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the monsoon port of Rainhaven. Brewer spreads the runs records across the table and picks up a sharp pencil. 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 <= 4000; 1 <= n <= 50; 1 <= coin <= 10^4.

Example 1:

Input: 2326 11 1 2654 2806 3401 4216 4485 7211 8554 8645 8899 9327
Output: 2326

Example 2:

Input: 1367 11 46 1467 1923 2643 6833 7274 7284 7725 9153 9374 9597
Output: -1

Example 3:

Input: 780 11 1818 2695 2860 2991 3482 4397 5197 5747 7707 7988 9062
Output: -1

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Teal runs of Brewer - MEDIUM Coding Problem | CodeTikki