#K12696. Maximum Items Purchase

    ID: 23748 Type: Default 1000ms 256MiB

Maximum Items Purchase

Maximum Items Purchase

You are given a budget B and N different item costs. The goal is to determine the maximum number of items that can be purchased with the given budget by always buying as many items as possible from the cheapest available cost first. The items have infinite supply and you may purchase as many items of each cost as your budget allows.

Mathematically, let \( c_1, c_2, \dots, c_N \) be the sorted list of costs in increasing order. For each cost \( c_i \), you can purchase \( \left\lfloor \frac{B}{c_i} \right\rfloor \) items, update the budget as \( B = B - c_i \times \left\lfloor \frac{B}{c_i} \right\rfloor \), and continue until the remaining budget is zero.

inputFormat

The input is provided via standard input (stdin) and consists of two lines:

  • The first line contains two space-separated integers \(N\) and \(B\), where \(N\) is the number of different items and \(B\) is the available budget.
  • The second line contains \(N\) space-separated integers representing the cost of each item.

outputFormat

Output a single integer to standard output (stdout) representing the maximum number of items that can be purchased under the given budget.

## sample
3 50
20 10 5
10