#C7389. Minimum Items Problem
Minimum Items Problem
Minimum Items Problem
You are given an array of positive integers \(nums\) representing the quantities of various items available, and a target integer \(T\). Your task is to determine the minimum number of items needed (an item can be used multiple times) so that their sum is exactly \(T\). If it is impossible to obtain \(T\) using any combination of the given items, print \(-1\).
Constraints:
- \(1 \leq n \leq 10^5\), where \(n\) is the number of items.
- \(1 \leq nums[i] \leq 10^4\)
- \(0 \leq T \leq 10^9\)
Example:
Input: 3 7 1 2 3</p>Output: 3
Explanation: One optimal solution is using items with values 1, 3, and 3 which sum to 7. Therefore, the answer is 3.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- First line: two space-separated integers \(n\) (the number of available items) and \(T\) (the target sum).
- Second line: \(n\) space-separated integers representing the values of the items.
outputFormat
Output a single integer to standard output (stdout) representing the minimum number of items required to achieve the target sum \(T\). If it is not possible, output \(-1\).
## sample3 7
1 2 3
3