#K38302. Maximize Delivery Weight

    ID: 26168 Type: Default 1000ms 256MiB

Maximize Delivery Weight

Maximize Delivery Weight

You are given m drones, each with a specific weight capacity, and n packages with given weights. Each drone can deliver a subset of the packages such that the total weight of the packages assigned to a drone does not exceed its capacity. Each package can be delivered by at most one drone.

Your goal is to maximize the total weight of the delivered packages over all drones.

The problem can be formalized as follows:

Given a set of drones with capacities \( c_1, c_2, \dots, c_m \) and a set of packages with weights \( w_1, w_2, \dots, w_n \), select a subset of packages for each drone such that for every drone \( i \), the sum of weights assigned does not exceed \( c_i \) and the overall sum of weights is maximized.

inputFormat

Input is read from standard input (stdin) as follows:

The first line contains an integer ( m ) representing the number of drones.

The second line contains ( m ) space-separated integers denoting the weight capacities of the drones.

The third line contains an integer ( n ) representing the number of packages.

The fourth line contains ( n ) space-separated integers representing the weights of the packages.

outputFormat

Output a single integer to standard output (stdout), which is the maximum total weight of packages that can be delivered without exceeding the capacity of any drone.## sample

3
10 20 15
4
5 8 6 5
24