#P3928. SAC E#1 - 一道简单题 Sequence2
SAC E#1 - 一道简单题 Sequence2
Description
Xiao Qiang likes sequences. One day, on a whim, he wrote down three sequences, each of length .
Amiba also likes sequences, but he only likes one type, the wave sequence.
Amiba told Xiao Qiang about his preference. Xiao Qiang plans to find the longest wave sequence within these three sequences.
That is, if we denote the three sequences as , he must construct a sequence of ordered pairs such that for any :
- .
- If , then .
- If , then .
- If , it only needs to keep the same direction within a segment (that is, for a contiguous segment with , either all satisfy , or all satisfy ).
Xiao Qiang wants this sequence of ordered pairs to be as long as possible.
Hint: When , the monotonicity is determined by , not by .
Clear version of the problem statement
Xiao Qiang gets a array. In each column, choose one number (or choose none), subject to the following conditions:
- If you choose from the first row, it must be greater than or equal to the previous number.
- If you choose from the second row, it must be less than or equal to the previous number.
- If you choose from the third row, then for any contiguous segment of numbers chosen from the third row, the directions must be the same (either all are less than or equal to the previous number, or all are greater than or equal to the previous number).
Input Format
The input contains lines.
The first line contains an integer , the length of the sequences.
The nd, rd, and th lines each contain integers, representing the three sequences, respectively.
Output Format
Output a single integer, the length of the longest wave sequence.
6
1 2 3 6 5 4
5 4 3 7 8 9
1 2 3 6 5 4
6
Hint
Constraints:
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , .
Here .
Sample explanation:
Take 1, 2, 3 from the third row (increasing), then take 6 from the first row (increasing), then take 5, 4 from the third row (decreasing), for a length of 6.
Translated by ChatGPT 5
京公网安备 11011102002149号