#P7425. [THUPC 2017] 机场
[THUPC 2017] 机场
Problem Description
An airport has parking stands. Among them, stands are connected to the terminal by boarding bridges, so passengers can board the plane directly through the bridge. The other stands are not connected to the terminal, so passengers must take a shuttle bus before boarding.
Obviously, taking a shuttle bus is a very bad experience, so every passenger who takes a shuttle bus will generate “unhappiness”.
Now you are given, for each flight, the number of passengers, the boarding time, and the departure time. A plane must choose an available stand at its boarding time; at this time all passengers finish boarding, and then the plane will stay at that stand until its departure time.
If a plane departs at time , then at time the stand where it was parked becomes available.
The airport management wants to minimize passengers’ unhappiness. To do this, a plane may change stands between its boarding time and departure time.
Suppose a plane starts switching from stand A to stand B at time . Then stand A is available at time . Such a switch is possible if and only if stand B is available at time .
Input Format
The input contains multiple test cases. The first line contains a positive integer representing the number of test cases. For each test case:
The first line contains three non-negative integers , representing the number of planes, the number of stands with boarding bridges, and the number of stands without boarding bridges.
The second line contains a floating-point number , given with at most two digits after the decimal point.
The next lines each contain three positive integers , describing a plane’s number of passengers, boarding time, and departure time.
Output Format
For each test case, output one line with one integer, representing the minimum unhappiness.
If it is impossible to arrange a valid plan so that all planes can complete boarding, output impossible.
2
3 1 1
0.5
1 1 5
1 1 5
1 1 5
6 2 2
0.5
4 1 4
4 2 7
8 4 8
8 4 8
10 5 9
1 7 9
impossible
7
Hint
The problem statement seems not to give an explicit formula for unhappiness. From the sample explanation, it can be inferred that:
Unhappiness (total number of people who take the shuttle bus) $+ \left\lfloor p \times \text{(number of passengers on the plane for each stand switch)} \right\rfloor$, summed over all switches.
Constraints
$1\le T\le 8,1\le n\le 200,0\le p\le1,1\le x\le 10^5,1\le s\le t\le10^9$.
Sample Explanation
Planes are numbered starting from .
At time , plane is assigned to boarding bridge A, and passengers start boarding. Currently, plane is at boarding bridge A.
At time , plane is assigned to boarding bridge B, and passengers start boarding. Currently, plane is at boarding bridge A, and plane is at boarding bridge B.
At time , plane switches to shuttle stand A. At this time, boarding bridge B is still unavailable.
At time , plane departs, plane arrives at shuttle stand A, plane is assigned to boarding bridge A, plane is assigned to boarding bridge B, and passengers of planes and start boarding. After boarding is completed, plane switches to shuttle stand B. At this time, neither boarding bridge A nor boarding bridge B is available.
At time , plane arrives at shuttle stand B, boarding bridge A becomes available, and plane is assigned to boarding bridge A and starts boarding. Currently: plane — boarding bridge A, plane — boarding bridge B, plane — shuttle stand B, plane — shuttle stand A.
At time , plane departs, and plane is assigned to shuttle stand A.
The unhappiness is (passengers of plane take the shuttle bus) (plane switches stands) (plane switches stands).
Copyright Information
From THUPC (THU Programming Contest, Tsinghua University Programming Contest) 2017.
Translated by ChatGPT 5