Subarray Sum

0

0 votes
Arrays, zyab, pre-computation
Problem

Given an array A of length N, your task is divide array into two non-empty subarray such that each of element present in the array must belong to exactly one subarray and the Good value is defined as the absolute difference between sum of both subarrays ( Let a be the sum of first subarray and b be the sum of second subarray , therefore it's Good Value is abs(ab) ). Your task is to find the minimum possible Good Value of array A.

 Input Format

The first line contains N, the size of array A

The second line contains N space seperated integers, the elements of A

 

Output Format

Output minimum Good Value possible for array A 

 

Constraints

2N2×105

1A[i]105

 

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

In the given test case, array A = { 6, 3, 7, 1, 2, 5 }

Two subarrays are {6, 3} and {7, 1, 2, 5} 

Absolute difference between their sum is abs( (6+3) - (7+1+2+5) ) = abs(9-15) = 6

Editor Image

?