#K68392. Equal Contiguous Subarray Sum Partition
Equal Contiguous Subarray Sum Partition
Equal Contiguous Subarray Sum Partition
Given an array of integers, determine whether there exists a contiguous subarray whose sum is equal to half of the total sum of the entire array. In other words, let ( S = \sum_{i=1}^{n} a_i ) and ( T = \frac{S}{2} ). Your task is to decide if there exists a non-empty contiguous subarray whose sum equals ( T ). Note that if ( S ) is odd, then such a partition is impossible.
For example, for the array [1, 5, 11, 5], the total sum ( S = 22 ) and ( T = 11 ). A valid contiguous subarray is [11] (or alternatively, the subarray from the second element to the third element yields a difference that indicates the existence of such a subarray), so the answer is YES.
inputFormat
The first line of the input contains an integer ( n ) representing the number of elements in the array. The second line contains ( n ) space-separated integers ( a_1, a_2, \dots, a_n ) representing the array elements.
outputFormat
Print a single line containing either "YES" if there exists a contiguous subarray whose sum is equal to half of the total sum of the array, or "NO" otherwise.## sample
4
1 5 11 5
YES