#C7080. Minimum Number of Drivers Problem

    ID: 50912 Type: Default 1000ms 256MiB

Minimum Number of Drivers Problem

Minimum Number of Drivers Problem

You are given M drivers, each with a maximum weight limit, and N parcels with specified weights. Your task is to determine the minimum number of drivers required such that all parcels can be delivered without exceeding any driver’s capacity.

The problem can be described mathematically as follows: For each driver i with capacity \( C_i \) (after sorting in descending order) and a sequence of parcels with weights \( w_1, w_2, \dots, w_N \), assign as many consecutive parcels as possible to a driver without violating the inequality: \[ \sum_{j=k}^{l} w_j \le C_i \] where \( k \) is the starting index for that driver. The goal is to minimize the number of drivers used.

Note: If the parcels cannot be distributed among all available drivers, the algorithm should use as many drivers as possible until no more parcels can be assigned.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer T representing the number of test cases.
  • For each test case:
    • The first line contains two space-separated integers M (number of drivers) and N (number of parcels).
    • The second line contains M space-separated integers representing the maximum weight limits of the drivers.
    • The third line contains N space-separated integers representing the weights of the parcels.

All numbers are positive integers.

outputFormat

For each test case, output a single line to standard output (stdout) containing the minimum number of drivers required to deliver all the parcels.

## sample
1
1 1
100
50
1

</p>