#K8636. Split Array into Two Equal Sum Subarrays
Split Array into Two Equal Sum Subarrays
Split Array into Two Equal Sum Subarrays
You are given an array of ( n ) integers. Your task is to determine whether there exists an index ( i ) (with ( 1 \le i < n )) such that the sum of the first ( i ) elements is equal to the sum of the remaining ( n-i ) elements. In other words, can the array be split into two non-empty contiguous subarrays with equal sums?
Formally, given an array ( a ) of size ( n ), check if there exists an index ( i ) so that:
[
\sum_{j=1}^{i} a_j = \sum_{j=i+1}^{n} a_j
]
If such an index exists, print YES
, otherwise print NO
.
inputFormat
The first line contains a single integer ( n ) (( 2 \le n \le 10^5 )) — the size of the array. The second line contains ( n ) integers ( a_1, a_2, \ldots, a_n ) (( |a_i| \le 10^9 )) representing the elements of the array.
outputFormat
Output a single line containing YES
if the array can be split into two non-empty contiguous subarrays with equal sums, or NO
otherwise.## sample
6
1 2 3 4 5 5
YES