Woburn Challenge 2017-18 Finals Round - Senior Division
The Party of Extraterrestrial Gangsters are not at all pleased with how their invasion of Earth is going so far. Their soldiers on the ground are losing in combat to the well-prepared battalions of cows and monkeys, and their nuclear bomb has been defused with particular ease. Fortunately for them, PEG's space battleship is also outfitted with an enormously powerful vaporizer beam capable of wiping out Scarberia in an instant. The PEG leaders were hoping to avoid resorting to such a merciless tactic, but they're running out of alternatives. However, before proceeding with any vaporization, they'll issue an ultimatum to the Scarberian leaders, detailing the amount of potential destruction and providing an opportunity for unconditional surrender instead.
Downtown Scarberia has a row of skyscrapers, numbered to from left to right. Skyscraper has a height of stories , and is occupied by citizens .
The PEG leaders have come up with a list of possible plans of attack using their vaporizer beam. The -th plan is defined by three integers, , , and . It consists of two phases, as follows:
- The beam will lock onto the tallest remaining un-vaporized skyscraper, and vaporize it. If there are multiple such skyscrapers with equal heights, they'll choose one of them uniformly at random. They'll repeat this process times, meaning that exactly skyscrapers will get vaporized in this phase.
- The beam will vaporize all of the un-vaporized skyscrapers numbered between and , inclusive. Note that some of these skyscrapers may have already been vaporized in phase 1 of the attack, meaning that anywhere between and skyscrapers (inclusive) will get vaporized in this phase.
For each possible plan of attack, the PEG leaders are interested in the expected number of citizens who would get vaporized in it (that is, the expected total number of citizens occupying all of the vaporized skyscrapers). Disclosing these statistics in an ultimatum would be sure to drive the Scarberian forces to immediately surrender! Help them determine this value for each of the plans of attack. Note that none of the plans will actually be executed (yet), meaning that no vaporization will carry over between them.
Subtasks
In test cases worth of the points, , , and
for each .
In test cases worth another of the points, and
.
Input Specification
The first line of input consists of a single integer, .
lines follow, the -th of which consists of two space-separated
integers, and , for .
The next line consists of a single integer, .
lines follow, the -th of which consists of three space-separated
integers, , , and , for .
Output Specification
Output lines, the -th of which contains a single real number, the
expected number of citizens who would get vaporized in the -th plan of
attack.
Your answer must have at most absolute or relative error
compared to the judge's answer to be considered correct.
Sample Input
5
4 1
2 50
6 400
4 100
3 33
3
5 1 5
4 2 2
2 2 4
Sample Output
584.0
584.0
550.5
Sample Explanation
In the first plan of attack, all skyscrapers would already get vaporized in the first phase.
In the second plan of attack, the tallest skyscrapers would get vaporized in the first phase, leaving just skyscraper behind, which would happen to get targeted in the second phase anyway.
In the third plan of attack, phase would involve vaporizing skyscraper 3 followed by either skyscraper or , with probability each. In the end, either or citizens would be vaporized, with probability each (depending on the skyscraper chosen in phase ).
Comments