PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000005. Đổi tiền ít đồng nhất (Minimizing Coins)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đổi tiền ít đồng nhất (Minimizing Coins)
Minimizing Coins
Source: CSES
Problem Statement
You are given coin denominations . All denominations are pairwise distinct, and an unlimited number of coins of each denomination is available.
Choose coins whose total value is exactly , minimizing the number of coins used. If this is impossible, the answer is -1.
Input
The first line contains and : the number of denominations and the target sum.
The second line contains integers , the denominations.
Output
Print the minimum number of coins with total value , or -1 if no such selection exists.
Subtasks
- Subtask 1 (20 points): ; ; (); the values are pairwise distinct.
- Subtask 2 (30 points): ; ; (); the values are pairwise distinct.
- Subtask 3 (50 points): ; ; (); the values are pairwise distinct.
Examples
Input
3 11
1 5 7
Output
3
Explanation
Using two -value coins and one -value coin gives with coins. No combination of one or two coins from denominations totals .