#C9922. Drone Delivery Optimization

    ID: 54069 Type: Default 1000ms 256MiB

Drone Delivery Optimization

Drone Delivery Optimization

You are given a fleet of D drones and a list of T delivery tasks. Each drone has a battery life and each delivery task requires some battery power. Your goal is to compute the maximum number of deliveries that can be completed without exceeding the battery life of any drone.

For each drone i with battery life \(B_i\) and each delivery task with required battery \(r_j\), a drone can perform several tasks sequentially provided that the cumulative battery consumption does not exceed \(B_i\). Formally, if a drone performs tasks \(j_1, j_2, \dots, j_k\), then it must satisfy:

[ \sum_{m=1}^{k} r_{j_m} \le B_i ]

You should maximize the total number of tasks performed across all drones.

inputFormat

The first line contains two integers, D and T, where D is the number of drones and T is the number of delivery tasks. The second line contains D space-separated integers representing the battery lives of the drones. The third line contains T space-separated integers representing the battery consumption required for each delivery task.

outputFormat

Output a single integer which represents the maximum number of delivery tasks that can be completed.

## sample
3 6
10 20 15
5 7 8 4 12 6
5