#P11833. Moving Boxes on a Number Line

    ID: 13933 Type: Default 1000ms 256MiB

Moving Boxes on a Number Line

Moving Boxes on a Number Line

You are given an infinitely long number line with (n) boxes. At time 0, the (i)-th box is positioned at (a_i) (for (1 \le i \le n)). For each box (i), you want that from time (t_i) onward, the box remains at (b_i). It is guaranteed that the sequences (a_1, a_2, \ldots, a_n) and (b_1, b_2, \ldots, b_n) are strictly increasing.

At each unit of time starting from time 0, you may perform at most one move. In a move, you can choose any box currently at position (p_i) and move it one unit to the left or right; formally, choose a direction (d \in {+1, -1}) such that the adjacent position (p_i + d) is unoccupied, and shift the box there. Alternatively, you may choose to do nothing during that time unit.

Determine whether it is possible to plan a sequence of moves so that, for every box (i), the box reaches (b_i) by time (t_i) and remains there indefinitely.

Note: Because only one move can be executed in each time unit, the total number of moves executed up to any time (T) cannot exceed (T). Each box (i) requires at least (|b_i - a_i|) moves to reach its target. Thus, a necessary and sufficient condition is that the moves required for the boxes (if optimally interleaved) do not exceed their respective deadlines. This can be checked by sorting the boxes by their deadlines (t_i) and ensuring that for each prefix of boxes, the cumulative moves are at most the corresponding deadline.

inputFormat

The first line contains a single integer (n) ((1 \le n \le 200,000)) indicating the number of boxes.

The second line contains (n) integers (a_1, a_2, \ldots, a_n) in strictly increasing order, representing the initial positions of the boxes.

The third line contains (n) integers (t_1, t_2, \ldots, t_n), where (t_i) is the deadline by which the (i)-th box must reach its target.

The fourth line contains (n) integers (b_1, b_2, \ldots, b_n) in strictly increasing order, representing the target positions of the boxes.

outputFormat

Output a single line containing (YES) if it is possible to achieve the desired configuration under the given constraints, or (NO) otherwise.

sample

3
1 2 3
3 6 10
2 4 6
YES