#P9422. [蓝桥杯 2023 国 B] 合并数列
[蓝桥杯 2023 国 B] 合并数列
Problem Description
Xiaoming found that there are many ways to split a very large positive integer into the sum of several positive integers. He chose two of these ways and listed them as two arrays and . The sums of the two arrays are the same.
Define one merge operation as merging two adjacent numbers in an array into one new number, whose value is the sum of the original two numbers. Xiaoming wants to make the two arrays exactly the same after several merge operations, i.e., and for any index , . Please compute the minimum number of merge operations needed to achieve Xiaoming's goal.
Input Format
The input has lines.
The first line contains two positive integers .
The second line contains integers separated by spaces.
The third line contains integers separated by spaces.
Output Format
Output line containing one integer.
4 3
1 2 3 4
1 5 4
1
Hint
Sample Explanation
You only need to merge and . Array becomes , which is the same as .
Test Case Scale and Constraints
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , .
The 14th Lanqiao Cup Software Contest Final, C/C++ University Group B, Problem D.
Translated by ChatGPT 5