#C8454. Equal Sum Non-Overlapping Subarrays
Equal Sum Non-Overlapping Subarrays
Equal Sum Non-Overlapping Subarrays
You are given an array of n integers. Your task is to determine whether there exist two non-overlapping contiguous subarrays that have the same sum.
A subarray is defined as a contiguous segment of the array. Two subarrays, indexed from i to j and k to l, are non-overlapping if either j < k
or l < i
.
You may find it useful to consider the prefix sum of the array. The sum of a subarray from index i to j can be computed as:
where \(P[k]\) denotes the sum of the first \(k\) elements of the array (with \(P[0]=0\)).
If such two subarrays exist, output YES
; otherwise, output NO
.
inputFormat
The input is read from standard input (stdin) and has the following format:
T N a1 a2 ... aN ... (repeated T times)
Where:
T
is the number of test cases.- For each test case, the first line contains an integer
N
representing the length of the array. - The next line contains
N
space-separated integers representing the array elements.
outputFormat
For each test case, print a single line to standard output (stdout) containing YES
if there exist two non-overlapping subarrays with the same sum, and NO
otherwise.
1
5
1 2 3 6 3
YES