#C4968. Minimum Weight Count

    ID: 48564 Type: Default 1000ms 256MiB

Minimum Weight Count

Minimum Weight Count

You are given a list of available weights and a target weight \( T \). Your task is to determine the minimum number of weights required to exactly sum up to \( T \) using a greedy strategy. The greedy strategy works by first sorting the weights in descending order and then repeatedly taking the largest weight that does not cause the cumulative sum to exceed \( T \).

If it is not possible to exactly reach the target weight with the given weights, output Infinity.

Note: When \( T = 0 \), the required count is 0.

inputFormat

The input is read from standard input and consists of three lines:

  • The first line contains a single integer \( n \), the number of available weights.
  • The second line contains \( n \) space-separated integers representing the available weights.
  • The third line contains a single integer \( T \), the target weight.

outputFormat

Output the minimum number of weights required to reach the target weight \( T \) on a single line. If it is impossible to reach \( T \) with the given weights, output Infinity.

## sample
3
1 2 3
5
2

</p>