#K13656. Count of Failed Parkings

    ID: 23961 Type: Default 1000ms 256MiB

Count of Failed Parkings

Count of Failed Parkings

You are given several parking lots, each with a fixed capacity. A series of drivers arrive sequentially; each driver requires a specified amount of parking space. For each driver, the parking process is as follows:

  • The driver will try to park in the parking lots in the given order.
  • If a parking lot has enough free space (greater than or equal to the driver's requirement), the driver parks there and the free space of that lot decreases by the driver's requirement.
  • If no parking lot can accommodate the driver immediately, the driver is considered to have failed to park.

Given the capacities of the parking lots, the parking space requirements of each driver, and additional duration information (which is not used in the parking decision), your task is to determine the number of drivers that fail to find a spot immediately upon arrival for each test case.

The process can be mathematically interpreted as follows: if the free capacity of a parking lot is \( f \) and the requirement is \( r \), then the driver can park if \( f \ge r \). Otherwise, the driver counts as a failure.

inputFormat

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

T
N
c1 c2 ... cN
M
r1 r2 ... rM
d1 d2 ... dM
... (repeat the above for each test case)

Where:

  • T is the number of test cases.
  • For each test case:
    • N is the number of parking lots.
    • The next line contains N integers representing the capacity of each parking lot.
    • M is the number of drivers.
    • The next line contains M integers representing the space requirement for each driver.
    • The next line contains M integers representing the parking durations for each driver (this value is provided but not used in the decision process).

outputFormat

For each test case, output a single integer on a new line representing the number of drivers who fail to park immediately. The output is written to stdout.

## sample
4
3
10 5 8
5
3 6 2 5 4
2 3 1 4 2
2
10 10
3
3 4 2
2 5 1
3
1 1 1
3
3 2 1
2 1 1
2
4 6
4
5 6 2 3
1 4 2 3
1

0 2 2

</p>