In honor of Taekhee's graduation
Time limit3sMemory limit128 MB
Deer bounce on a line segment [0,T], each with strength; a statue at x falls when the net force of deer that have reached it exceeds W. Maximize the fall time over x.
- Level
Hard9 of 10
- Topics
- Math, Simulation, Prefix sum, Sorting
- Solved
- No attempts yet
Problem
After a long undergraduate career, Taekhee left the campus. Dohyun decided to put up a statue in his honor and picked the ground for it. The ground forms a number line, so the statue goes on a single point of that line, and the point does not have to be an integer coordinate.
While the statue was being finished, deer came down from a nearby hill. The deer run along the same number line at a constant speed and never look back. A deer that reaches the left end turns right, a deer that reaches the right end turns left, and no deer leaves the ground. Dohyun decided to put up the statue anyway. He wants it to stand as long as possible before it falls.
Dohyun found out the following.
- A deer and the statue are points with no size.
- Each deer has a starting point and a facing direction (left or right), and it runs in that direction at distance 1 per second. When it reaches one end of the number line, it turns around and keeps running. When two deer meet, they pass through each other and nothing happens.
- Deer has strength . A deer that reaches the statue stops there and pushes the statue forever. It pushes in the direction it was facing at the moment it arrived.
- A push from the left and a push from the right cancel each other. For example, if one deer pushes with strength 3 from the left and another pushes with strength 2 from the right, the statue receives a force of 1 to the right.
- If the statue stands on the starting point of some deer, that deer does not run at all and pushes the statue from the start, in the direction it faces.
- The statue has durability . The moment the force on the statue exceeds in either direction, the statue falls.
- If two deer reach the statue at the same moment, their two forces are added at once, with no order between them.
The moment the statue falls depends on where it stands. Find how long the statue lasts when the position is chosen as well as possible.
Input
The first line contains three integers , , : the number of deer, the largest coordinate of the number line, and the durability of the statue. (, , )
The smallest coordinate of the number line is always .
The -th of the next lines contains three integers , , : the starting position, the initial facing direction, and the strength of deer . Deer faces left if and right if . (, or , )
Every deer runs at the same speed of distance 1 per second.
Output
Fix a position for the statue and the moment the statue falls is fixed as well. Call that moment . It is the first moment the force on the statue exceeds , and when no such moment exists.
If for at least one position , print inf on the first line.
Otherwise print on the first line the supremum, that is the least upper bound, of over all real positions with . Moving the statue a little can bring arbitrarily close to a value that no position reaches exactly. That value is still the answer.
The answer is always a multiple of , so print it with exactly one digit after the decimal point. Print 9.5 for an answer of nine and a half, and 10.0 for an answer of ten.
Hint
In the first example, put the statue at . At time deer 3 and deer 4 arrive together and leave a force of 4 from the right to the left. At time deer 2 arrives and the force drops to 0. At time deer 1 arrives, the force becomes 20, and the statue falls. No position lasts longer.
In the second example, put the statue at . At time deer 1 and deer 2 arrive together and leave a force of 4 from the right to the left. At time deer 3 arrives from the left and deer 4 arrives from the right, so the force becomes from the left to the right. The durability is 10, so the statue does not fall, and no deer is left to arrive.
In the third example every deer has strength 3 and the durability is 2, so the statue falls the moment any single deer reaches it. For a position with , the first deer to arrive comes at time , and this value approaches 2 as approaches 1. At exactly , deer 2 stands on the statue and pushes it right away, so the statue falls at time 0. No position lasts a full 2 seconds, and the answer is 2.0.