Maxwell's Demon
Time limit6sMemory limit1024 MB
Find the earliest time at which the demon can move all red particles into the left chamber and all blue particles into the right chamber.
- Level
Medium7 of 10
- Topics
- Math, Simulation, Greedy
- Solved
- No attempts yet
Problem
Relax: no knowledge of thermodynamics is needed to solve this problem.
Maxwell's demon sits in a container of height and width . The container is divided into two adjacent chambers, each of height and width . An impenetrable wall separates the two chambers, and the demon sits at a fixed position on this center wall.
The chambers contain particles. Each particle has a position, a velocity, and a color. When a particle strikes the wall of a chamber, it reflects off the wall with perfect elasticity. Figure H.1 shows a container with two particles, a blue one in the left chamber and a red one in the right chamber.

Figure H.1: The first sample input. The demon is shown enlarged in gray, but in reality it is infinitesimally small and has no face.
Maxwell's demon wants to reduce entropy by sorting the particles. All red particles should end up in the left chamber, and all blue particles should end up in the right chamber. To do this, the demon can let particles pass through the center wall when they hit the demon's position.
The chamber bottoms lie on the -axis, and the center wall runs along the positive -axis. At any time the demon chooses, every particle at the demon's position can pass through to the other chamber instead of reflecting off the wall, keeping its velocity. The demon can do this whenever and as often as it wants. It can also refuse to let a particle through even when the particle hits the demon's position. However, if several particles are at at the same time, either all of them pass through or all of them reflect.
Help the demon sort the particles. What is the earliest time at which all red particles can be in the left chamber and all blue particles can be in the right chamber?
Input
The first line contains five integers , , , , and . Here and () are the width and height of each chamber, () is the -coordinate of the demon's position on the center wall, and and ( and ) are the numbers of red and blue particles.
The next lines each describe one particle with four integers , , , . Here (, ) is the initial position, and (, , ) is the initial velocity. The first particles are red, and the remaining particles are blue.
Output
Output the least amount of time needed for all red particles to be in the left chamber and all blue particles to be in the right chamber. Your answer must have an absolute or relative error of at most . If it is impossible for this to happen within a finite amount of time, output impossible.