Segment Union
Time limit5sMemory limit1024 MB
Given centers x_i and radii a_i, sum the union length of the intervals [x_i - r, x_i + r] over all ways to assign the radii to the centers, modulo 1e9+7.
- Level
Hard9 of 10
- Topics
- Sorting, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
There are positive integers and another positive integers .
Let be a permutation of . Initially, the entire number line is white. For each , the segment is colored black. is the total length of the black segments on the number line. For example, if , , and are colored black, the total length of the black segments is .
Find the sum of over all permutations of , modulo .
Input
The first line contains a single integer ().
The second line contains space-separated integers ().
The third line contains space-separated integers ().
Output
Output a single integer, the sum of over all permutations of , modulo .
Hint
Values may repeat. Different permutations that produce the same sequence of values are still counted separately.
Print the answer modulo .