#C10158. Maximum Wizards Consuming Fruits

    ID: 39332 Type: Default 1000ms 256MiB

Maximum Wizards Consuming Fruits

Maximum Wizards Consuming Fruits

In this problem, you are given T test cases. For each test case, there are N trees and M wizards. Every tree has a magical fruit with a certain power value given by an array (P) of length N, and each wizard has a magical consumption limit given by an array (L) of length M. A wizard can successfully consume fruits if there exists at least one contiguous subarray of trees (i.e. a segment of (P)) such that the sum of the fruit powers in that segment does not exceed his consumption limit. Formally, for a wizard with limit (L_i), we require that there exist indices (1 \le i \le j \le N) satisfying: [ \sum_{k=i}^{j} P_k \le L_i ] Your task is to determine, for each test case, the maximum number of wizards who can successfully consume fruits.

The input is read from standard input and the output should be written to standard output.

inputFormat

The first line contains an integer (T) representing the number of test cases. For each test case:

  • The first line contains two integers (N) and (M) separated by a space, where (N) is the number of trees and (M) is the number of wizards.
  • The second line contains (N) space-separated integers, representing the array (P) (the magical power of each tree).
  • The third line contains (M) space-separated integers, representing the array (L) (the magical consumption limits of the wizards).

outputFormat

For each test case, print a single integer on a new line indicating the maximum number of wizards that can successfully consume fruits.## sample

1
5 3
10 20 30 40 50
60 70 80
3

</p>