#P14785. [NERC 2025] Doorway
[NERC 2025] Doorway
题目描述
The construction of the doorway for the Nonsense Engineering and Research Convention was delegated to one of the future attendees, who decided on a multi-layered sliding door design.
Each layer can be described as a horizontal interval, bounded by solid walls on the left and right, containing a number of sliding doors of fixed lengths. Within a layer, each door can move independently to the left or right, as long as it does not overlap other doors or the walls. All layers are parallel and stacked vertically.
After construction, the organizers noticed a problem: it is difficult to fully open the door, and since a large number of attendees are expected, they need to create the largest possible opening to allow everyone to pass through freely.
The size of the opening is defined as the total length of horizontal intervals such that, at every point of such an interval and in every layer, there is neither a door nor a wall. Your task is to determine the largest possible opening, given the doors’ layout.
输入格式
The first line contains an integer () — the number of layers of the door.
Each of the next lines starts with three integers , , (; ) — the number of sliding doors on that layer and the -coordinates and of the walls on that layer. There is a wall at and a wall at ; all positions with or are blocked by walls.
They are followed by integers (; ) — the lengths of the sliding doors on that layer given in order from the leftmost door to the rightmost.
It is guaranteed that .
输出格式
Output a single integer — the size of the largest possible opening that can be achieved by moving the sliding doors on each layer.
2
2 2 11 3 2
3 4 12 1 1 2
4
2
2 0 7 2 4
1 4 9 4
0
提示
This illustration shows a solution for the first example. Walls are filled with black color, doors are filled with various shades of grey, the opening is white. When first doors on each layer are shifted to the left and the rest of the doors to the right, we get the largest opening of .
:::align{center}
:::