Hongjun's Intersection
Time limit2sMemory limit512 MB
Sum the lengths of the intersections of all k-subsets of given segments, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Sorting, Combinatorics, Prefix sum
- Solved
- No attempts yet
Problem
There are one dimensional segments on a horizontal line. Call the -th segment (). The length of a segment is , and the length of the empty set is .
You are given a positive integer with . For every way of choosing distinct segments, add up the length of the intersection of the chosen segments:
Write a program that computes this sum.
The answer can be very large, so print it modulo .
Input
The first line contains and . ()
Each of the next lines contains two integers and describing the -th segment. ()
Output
Print on one line the sum of the intersection lengths over every way of choosing distinct segments, modulo .
Hint
When the segments are , , and , there are three ways to choose, and the intersection lengths are:
So the answer is .