#C9575. Can Three Parts Equal Sum?
Can Three Parts Equal Sum?
Can Three Parts Equal Sum?
You are given an array of integers. Your task is to determine whether the array can be split into three contiguous non-empty parts such that the sum of the elements in each part is equal.
Let the total sum of the array be \(S\). For the array to be partitioned into three parts with equal sum, \(S\) must be divisible by 3. Each part must then have a sum of \(\frac{S}{3}\). Traverse the array and attempt to form segments where the cumulative sum equals \(\frac{S}{3}\). If you can form at least 3 such segments, output True
; otherwise, output False
.
Note: The three segments must be contiguous and non-empty.
inputFormat
The input is read from standard input (stdin). The first line contains a single integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers representing the array.
outputFormat
Output a single line to standard output (stdout) with either "True" if the array can be partitioned into three non-empty parts with equal sums, or "False" otherwise.## sample
11
0 2 1 -6 6 -7 9 1 2 0 1
True
</p>