#P1728. Parking Lot Car Rearrangement
Parking Lot Car Rearrangement
Parking Lot Car Rearrangement
You are given a parking lot which is a long rectangle with a fixed width \(w\) and infinite length to the right. The coordinate system is established with the lower‐left corner as the origin \((0,0)\) and the axes parallel to the sides of the rectangle. There are \(n\) cars parked in the lot. Each car is an axis-aligned rectangle (i.e. its edges are parallel to the coordinate axes) and may have different dimensions. You are allowed to translate (i.e. shift) a car arbitrarily (without rotation) as long as:
- The car always remains completely within the parking lot boundaries (i.e. its \(y\)-coordinates are between \(0\) and \(w\)); note that there is no right boundary.
- No two cars ever overlap during the movement (though they may touch each other, meaning the overlapping area can be \(0\) at any moment).
You are given both the initial positions and the boss’s desired positions for all cars. For each car, the initial position is given by its bottom‐left and top‐right coordinates, \((x, y)\) and \((x_2, y_2)\). The car’s dimensions are thus \(\text{width} = x_2 - x\) and \(\text{height} = y_2 - y\). In the target configuration, you are given the desired bottom‐left coordinate \((t_x, t_y)\); the top‐right coordinate is implicitly \((t_x + (x_2-x),\, t_y + (y_2-y))\). Both the initial and desired configurations are guaranteed to be non-overlapping (cars may touch but not overlap). Determine whether it is possible to re-arrange the cars from the initial configuration to the boss’s desired configuration following the rules above.
Note: Since the lot extends infinitely to the right, you can always shift a car arbitrarily far to the right to avoid collisions temporarily. The only strict constraints are keeping the car within the vertical \([0, w]\) boundaries and ensuring that no overlapping occurs during the moves.
Output YES if the re-arrangement is possible, or NO otherwise.
inputFormat
The first line contains two integers \(n\) and \(w\) where \(n\) is the number of cars and \(w\) is the width of the parking lot.
Then \(n\) lines follow. Each line contains 6 integers:
- \(x\) \(y\) \(x_2\) \(y_2\) \(t_x\) \(t_y\)
Here, \((x, y)\) and \((x_2, y_2)\) are the bottom‐left and top‐right coordinates of a car's initial position, and \((t_x, t_y)\) is the bottom‐left coordinate of its desired position. The desired top‐right coordinate is \((t_x + (x_2-x),\, t_y + (y_2-y))\). It is guaranteed that in both configurations, the cars do not overlap (touching boundaries is allowed). The parking lot’s vertical boundary is \([0, w]\) (i.e. every car must always satisfy \(0 \le y \le y_2 \le w\)).
outputFormat
Output a single line with YES
if it is possible to re-arrange the cars from the initial positions to the target positions following the rules. Otherwise, output NO
.
sample
2 10
0 0 2 3 0 0
3 3 5 8 2 5
YES