#P7244. 章节划分
章节划分
Background
During essay week, as the name suggests, you write one essay a day, producing a lot of work.
Xiao Huimao’s essays have been “publicly executed” by the teacher countless times. Yesterday, her own grandma turned into someone else’s “maternal grandma” in another essay; today, the noodles she finally managed to write about became someone else’s hot and sour rice noodles tomorrow. Once you use your material, it is basically ruined, qwq.
So, unwilling to give up, Xiao Huimao decided to be even more productive.
Problem Description
Tianyi has decided on pieces of material, and they will be written in order in the essay. The theme feature value of the -th piece of material is .
However, Tianyi found that her masterpiece is far too long, so she wants to split them into exactly chapters. Each chapter contains a contiguous and non-empty segment of materials. Suppose the -th chapter contains materials . Tianyi will choose the material with the largest theme feature value to refine the idea, obtaining the theme value of this chapter, satisfying .
Finally, the conciseness of the whole essay is the greatest common divisor of the theme values of all chapters, i.e., .
Tianyi of course wants to maximize the conciseness of the essay. What is the maximum possible value of the conciseness?
Simplified statement
Given a sequence of length , you must split it into exactly contiguous and non-empty segments. Define the theme value of the -th segment as the maximum of all elements in that segment, denoted by . You need to maximize and output this maximum value.
Input Format
The first line contains two integers , representing the length of the materials and the number of chapters to split into.
The second line contains integers, representing the theme feature value of each piece of material.
Output Format
Output one integer in a single line, representing the answer.
5 3
1 3 2 9 6
3
5 2
10 2 5 5 5
5
Hint
Sample explanation 1
There may be multiple optimal ways to split the materials. Here is one optimal split: divide these materials into chapters: . Then , and the maximum conciseness is .
Constraints and notes
This problem uses bundled testdata.
For of the testdata, , .
| Subtask | Points | |||
|---|---|---|---|---|
| 1 | 5 | / | / | |
| 2 | 10 | |||
| 3 | / | |||
| 4 | 15 | |||
| 5 | 20 | / | ||
| 6 | 10 | / | ||
| 7 | 30 | / |
Translated by ChatGPT 5