Maxdifficent Group
문제
Given an array of integers where N ≥ 2. Each element in A should be assigned into a group while satisfying the following rules.
- Each element belongs to exactly one group.
- If and where belongs to the same group, then where i ≤ k ≤ j also belongs to the same group as and .
- There is at least one pair of elements that belong to a different group.
Let denotes the group ID of element . The cost of a group is equal to the sum of all elements in that belong to that group.
Two different group IDs, and (where ), are adjacent if and only if is either or for every i ≤ k ≤ j. Finally, the value of two group IDs and is defined as the absolute difference between and .
\text{diff}(x, y) = |\text{cost}(x) − \text{cost}(y)|
Your task in this problem is to find a group assignment such that the largest value between any pair of adjacent group IDs is maximized; you only need to output the largest value.
For example, let A_{1..4} = \{100, −30, −20, 70\}. There are ways to assign each element in into a group in this example; some of them are shown as follows.
- . There are pairs of group IDs that are adjacent and their values are:
- \text{diff}(1, 2) = |\text{cost}(1) − \text{cost}(2)| = |(100) − (−30)| = 130,
- \text{diff}(2, 3) = |\text{cost}(2) − \text{cost}(3)| = |(−30) − (−20)| = 10, and
- \text{diff}(3, 4) = |\text{cost}(3) − \text{cost}(4)| = |(−20) − (70)| = 90.
- The largest value in this group assignment is .
- . There are pairs of group IDs that are adjacent and their values are:
- \text{diff}(1, 2) = |\text{cost}(1) − \text{cost}(2)| = |(100) − (−30 + (−20))| = 150, and
- \text{diff}(2, 3) = |\text{cost}(2) − \text{cost}(3)| = |(−30 + (−20)) − (−20)| = 70.
- The largest value in this group assignment is .
The other group assignments are: , , , , , and . Among all possible group assignments in this example, the maximum largest that can be obtained is from the group assignment .
입력
Input begins with a line containing an integer (2 ≤ N ≤ 100\,000) representing the number of elements in array . The next line contains integers (-10^6 ≤ A_i ≤ 10^6) representing the array .
출력
Output contains an integer in a line representing the maximum possible largest that can be obtained from a group assignment.
예제
예제 1
4 100 -30 -20 50
150
예제 2
5 12 7 4 32 9
46
예제 3
6 -5 10 -5 45 -20 15
70