Smaller Averages
Time limit2sMemory limit1024 MB
Count the ways to split two length-N arrays into the same number of contiguous parts, where each a-part's average is at most its paired b-part's average, mod 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Prefix sum
- Solved
- No attempts yet
Problem
Bessie has two arrays of length (). The -th element of the first array is (), and the -th element of the second array is ().
Bessie wants to split both arrays into non-empty subarrays so that the following holds.
- Every element belongs to exactly one subarray.
- Both arrays are split into the same number of subarrays. Let this number be , so the first array and the second array are each split into exactly subarrays.
- For every , the average of the -th subarray from the left in the first array is less than or equal to the average of the -th subarray from the left in the second array.
Count the ways to split both arrays under these constraints, modulo . Two ways differ if the number of subarrays differs or if some element belongs to a different subarray.
Input
The first line contains . The next line contains . The next line contains .
Output
Output the number of ways to split both arrays under these constraints, modulo .