William is given an array of
His goal is such that after modifying this segment, the sum of the prefix sums is minimized. This value can be represented as:
Output the minimal value attainable under the given terms.
Input Specification
The first line consists of a single integer
The next line contains
Subtask 1 [20%]
Subtask 2 [80%]
No further constraints.
Output Specification
Output a single integer, the minimal value attainable of the expression outlined above.
Sample Input 1
Copy
4
1 -2 100 -5
Sample Output 1
Copy
-207
Explanation for Sample 1
If the segment
The prefix sum of the modified array is:
Thus the answer would be the sum of the prefix sum of all elements:
The value
Sample Input 2
Copy
5
-10 7 -2 -2 10
Sample Output 2
Copy
-78
Comments