#C11277. Maximum Pill Weight
Maximum Pill Weight
Maximum Pill Weight
You are given a set of ingredients, each with a specified weight. You can use each ingredient an unlimited number of times. Your task is to determine the maximum total weight that can be achieved without exceeding a given weight limit. This is equivalent to solving an unbounded knapsack problem.
Formally, given two integers ( n ) and ( W ) representing the number of ingredients and the weight limit respectively, and a list of ( n ) positive integers ( w_1, w_2, \dots, w_n ) representing the weights of the ingredients, find the maximum sum ( S ) such that ( S \leq W ) and ( S ) is formed by summing any number of the given weights (possibly repeated).
inputFormat
The input is given from standard input (stdin) in the following format:
The first line contains two space-separated integers ( n ) and ( W ), where ( n ) is the number of ingredient types and ( W ) is the maximum allowed weight.
The second line contains ( n ) space-separated integers, each representing the weight of an ingredient. If ( n = 0 ), the second line will be empty.
outputFormat
Output a single integer to standard output (stdout), representing the maximum weight that can be achieved without exceeding the weight limit ( W ).## sample
3 10
2 3 7
10