Given a random start time in [t1,t2] and fixed measurement offsets, find the probability that no measurement lands inside any forbidden interval.
Medium7IntervalsMathSortingImplementationNo attempts yetTime limit2sMemory limit512 MBA space probe is out of control. It starts its measurement sequence at some time t, measured in seconds, that lies between t1 and t2, and nobody knows exactly when. Every start time t in the interval [t1,t2] is equally likely.
The measurement sequence is preprogrammed and cannot be changed. It consists of n successive measurements whose offsets m1,m2,…,mn are fixed. If the sequence starts at time t, the first measurement happens at time t+m1, the second at time t+m2, and the last one at time t+mn. A measurement is instantaneous, so its duration is 0 seconds.
The probe rotates in space and cannot be steered. Because of the rotation there are stretches of time during which the measuring devices point at the Sun. A measurement taken while a device points at the Sun destroys its sensors and the whole probe is lost. The trajectory and the rotation are known, so the k time intervals [b1,e1],[b2,e2],…,[bk,ek] during which no measurement may be taken are known as well.
Compute the probability that every measurement succeeds and the probe is not lost to solar radiation.
All given times and interval lengths are integers. Only the start time of the sequence is unknown, and it may be any real number in [t1,t2].
The first line contains four integers n, k, t1, t2. Here n is the number of measurements, k is the number of time intervals in which no measurement may be taken, and t1 and t2 bound the window in which the measurement sequence can begin.
The second line contains n integers m1,m2,…,mn, the offsets at which the measurements happen after the sequence begins. The sequence mi is strictly increasing.
Each of the following k lines contains two integers bj and ej that describe one forbidden interval [bj,ej]. It is guaranteed that bj<ej and that the intervals do not overlap, that is, ej−1<bj for every j>1.
Values on one line are separated by single spaces.
Print the probability that the probe survives, that is, the probability that no measurement falls inside any forbidden interval.
Every input value is an integer, so this probability is a rational number. Print it as an irreducible fraction in the form p/q, with no space around the slash, where q>0 and gcd(p,q)=1. Print a probability of 0 as 0/1 and a probability of 1 as 1/1.