Each hearing has a start time and a uniform integer length in [a,b]; pick hearings to attend fully so the expected count is maximized.
Hard8Dynamic programmingProbabilitySortingBinary searchNo attempts yetTime limit2sMemory limit512 MBYou have a trip to Washington D.C. coming up, and you want to sit in on as many Congressional committee hearings as you can. Your representative gave you a pass that admits you to the audience of any hearing. Three things make the schedule hard to plan.
Congress publishes the schedule well before your trip. For each hearing it gives the start time s and the values a and b, the shortest and the longest possible length of that hearing. The actual length is an integer drawn uniformly from the closed interval [a,b]. That is, the hearing starts at time s and ends at time s+L, where L is equally likely to be any integer with a≤L≤b.
Find a strategy that maximizes the expected number of hearings you attend. As an example, take four hearings with these values.
| hearing | s | a | b |
|---|---|---|---|
| Social media and elections | 1 | 1 | 7 |
| NASA missions | 3 | 2 | 3 |
| Oil and gas exploration | 5 | 1 | 4 |
| Hurricane recovery efforts | 6 | 10 | 10 |
For this schedule the optimal strategy reaches an expected value of 2.125 hearings. You begin with the NASA hearing, which starts at time 3 and ends at time 5 or at time 6 with equal probability, since its length is uniform over the set {2, 3}. If it ends at time 5 you go straight to the oil and gas exploration hearing, and with probability 1/4 that hearing ends at time 6, which lets you attend a third hearing on hurricane recovery. If the NASA hearing ends at time 6 instead, you go straight to the hurricane recovery hearing. This strategy gives you 3 hearings 12.5% of the time and 2 hearings the other 87.5% of the time, so the expected value is 2.125. Starting with the social media and elections hearing might get you to four hearings if you are lucky, but the best expected value from that start is only 2.10714.
The first line contains an integer n, the number of scheduled hearings (1≤n≤104). Each of the next n lines contains three integers s, a, and b: the start time, the minimum length, and the maximum length of one hearing (1≤s≤106, 1≤a≤b≤106). The hearings are listed in nondecreasing order of start time.
Print, on one line, the expected number of hearings attended under an optimal strategy, rounded to six digits after the decimal point. Always print all six digits, so a value of 1 is printed as 1.000000. In every test case the answer is away from a rounding boundary, so the direction of the rounding does not matter.