Subarray Sum

0

0 votes
Arrays, zyab, pre-computation
Problem

Given an array  of length , 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 ). Your task is to find the minimum possible Good Value of array .

 Input Format

The first line contains , the size of array 

The second line contains  space seperated integers, the elements of 

 

Output Format

Output minimum Good Value possible for array  

 

Constraints

 

Sample Input
6
6 3 7 1 2 5
Sample Output
6
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

?