#P10429. [蓝桥杯 2024 省 B] 拔河
[蓝桥杯 2024 省 B] 拔河
Problem Description
Xiaoming is a teacher at a school. There are students in his class, and the strength value of the -th student is . In his free time, Xiaoming decides to organize a tug-of-war contest in the class.
To make the two sides as evenly matched as possible, he needs to choose two teams from these students. The students in each team must have consecutive indices: $\{{a_{l_1}}, a_{l_1 + 1}, \dots, a_{r_1 - 1}, a_{r_1}\}$ and $\{{a_{l_2}}, a_{l_2 + 1}, \dots, a_{r_2 - 1}, a_{r_2}\}$, where .
The two teams do not have to have the same number of students, but the sums of the strength values within the two teams should be as close as possible. Please compute the minimum possible difference between the sums of strength values among all valid ways to pick the two teams.
Input Format
The input has two lines.
The first line contains a positive integer .
The second line contains positive integers .
Output Format
Output one line containing a non-negative integer, representing the minimum difference between the sums of strength values of the two teams.
5
10 9 8 12 14
1
Hint
Sample 1 Explanation
One optimal selection is:
Team : , Team : . The sums of strength values are and , so the difference is .
Constraints
- For of the testdata, .
- For all testdata, it is guaranteed that and .
Translated by ChatGPT 5