luogu#P7839. 「Wdoi-3」夜雀 singing
「Wdoi-3」夜雀 singing
Background
“Sigh, today has really been a troublesome day. But after a whole night of work is over, it’s finally time for me to show off my singing!”
As one of the fairies in Gensokyo, Mystia, when she has free time (that is, after the Night Sparrow Diner closes), also goes to a night sparrow singing party that is organized spontaneously by the night sparrows. The night sparrows sing in an agreed-upon way. At tonight’s party, Mystia becomes the organizer.
However, since everyone is a night sparrow, the so-called “stage” is actually made up of several trees of different heights. Night sparrows can fly (obviously), so they can keep changing their positions.
But because the number of night sparrows is simply too large, Mystia, as the organizer, cannot figure out the plan for organizing the event. Can you help her?
Problem Description
We number these trees from to . There are night sparrows participating in the party distributed on positions. The height of the -th tree is .
The singing party lasts for a total of time moments. At moment , the night sparrows can only sing on trees whose height is strictly greater than . Since these trees are chosen in advance, we always have . At each moment, a night sparrow may choose to stay still, or move to a tree with an adjacent index (for example, a night sparrow originally on the tree with index may move to index or at the next moment. However, they cannot move to the trees with index or ). The initial state is at moment . That is, if a night sparrow initially is on a tree of height , then at the next moment she must go to a tree with height greater than .
But in this way, some night sparrows may not be able to finish the party smoothly, and may encounter a situation of “nowhere to go”. So the night sparrows decide to choose some tall trees as flight points. If a night sparrow reaches a flight point, then at the next moment, besides moving to adjacent-index trees, she can also reach other flight points.
However, having too many flight points makes the party very chaotic. Therefore, Mystia wants to minimize the number of flight points. Can you help her?
Input Format
The first line contains three integers , with meanings as described above.
The second line contains integers, where the -th integer denotes .
The third line contains integers, where the -th integer denotes the position of the -th night sparrow.
Output Format
Output one line with one integer, denoting the minimum number of flight points.
5 3 4
1 2 1 4 5
5 3 2
2
10 7 9
8 1 1 5 13 10 1 1 6 3
2 4 7 10 6 8 9
3
Hint
Explanation of Sample 1
An optimal plan is to build flight points on trees and . The table below shows one feasible movement plan for each night sparrow:
$$\def\arraystretch{1.8} \begin{array}{|c|c|c|c|} \hline \textsf{\textbf{夜雀编号}} & \textsf{\textbf{时刻 $0$ 所在位置}} & \textsf{\textbf{时刻 $1$ 所在位置}} & \textsf{\textbf{时刻 $2 \sim 4$ 所在位置}} \cr\hline \textsf1 & 5 & 5 & 5 \cr\hline \textsf2 & 3 & 2 & 5 \cr\hline \textsf3 & 2 & 5 & 5 \cr\hline \end{array}$$It can be proven that there is no better solution.
Constraints and Notes
$$\def\arraystretch{1.6} \begin{array}{|c|c|c|c|}\hline \textbf{Subtask} & \bm{n\le} & \textbf{Special Property} & \textbf{Score} \cr\hline 1 & 16 & - & 15 \cr\hline 2 & 5\times 10^5 & \text{A} & 5 \cr\hline 3 & 5\times 10^5 & \text{B} & 15 \cr\hline 4 & 10^3 & - & 25 \cr\hline 5 & 5\times 10^5 & - & 20 \cr\hline 6 & 5\times 10^6 & - & 20 \cr\hline \end{array}$$- Special Property A: .
- Special Property B: and .
For of the testdata, , , . It is guaranteed that all are pairwise distinct, and .
Hint
Obviously, you can take all positions as flight points, and then at moment let all night sparrows fly to a tree with , obtaining a valid solution with answer . Therefore, this problem always has a solution.
Translated by ChatGPT 5