#K34167. Minimum Storage Units

    ID: 25250 Type: Default 1000ms 256MiB

Minimum Storage Units

Minimum Storage Units

You are given a set of storage unit sizes and several users’ storage requirements. Each storage unit size represents a standard capacity available in infinite supply. For each user, your task is to determine the minimum number of storage units needed such that the total capacity meets or exceeds the user’s requirement.

More formally, let the available storage sizes be \( s_1, s_2, \dots, s_n \) (in GB) and for a given user the storage requirement is \( R \) (in GB). You can use any number of storage units of each type. The greedy strategy is to sort the storage sizes in descending order and then, for each storage size, allocate as many units as possible. Specifically, for each storage size \( s \), you add \( \left\lfloor \frac{R}{s} \right\rfloor \) units and update \( R \) as \( R \mod s \). If after processing all sizes, there is a remainder \( R > 0 \), one extra unit is needed. Produce the minimum number of units required for each user.

Note: The problem expects you to use the input/output style of reading from standard input and writing to standard output.

inputFormat

The input consists of four lines:

  • The first line contains an integer \( n \) representing the number of available storage sizes.
  • The second line contains \( n \) space-separated integers denoting the storage sizes, each in GB.
  • The third line contains an integer \( m \) representing the number of users.
  • The fourth line contains \( m \) space-separated integers where each integer denotes the storage requirement of a user in GB.

outputFormat

Output a single line with \( m \) space-separated integers. Each integer corresponds to the minimum number of storage units required for the respective user.

## sample
3
10 20 30
4
35 45 25 60
2 3 2 2