#C4376. Equal Sum Non-Overlapping Subarrays

    ID: 47907 Type: Default 1000ms 256MiB

Equal Sum Non-Overlapping Subarrays

Equal Sum Non-Overlapping Subarrays

You are given an array of distinct integers. Your task is to determine whether there exist two non-overlapping subarrays that have the same sum.

A subarray is a contiguous segment of the array. Two subarrays are considered non-overlapping if the ending index of the first subarray is strictly less than the starting index of the second subarray.

Formally, given an array \(A\) of size \(n\), you need to determine if there exists a pair of subarrays \(A[i \ldots i+L-1]\) and \(A[j \ldots j+L-1]\) for some length \(L \ge 1\) with \(i + L \le j\) such that

[ \sum_{k=i}^{i+L-1} A[k] = \sum_{k=j}^{j+L-1} A[k]. ]

If such a pair exists, print YES; otherwise, print NO.

Note: It is guaranteed that all integers in the array are distinct.

inputFormat

The input is given from stdin and consists of multiple test cases. The first line contains a single integer \(T\) (\(1 \le T \le 100\)) representing the number of test cases. Each test case is described as follows:

  • The first line contains a single integer \(n\) (\(1 \le n \le 1000\)), the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the elements of the array.

All array elements are distinct.

outputFormat

For each test case, output a single line containing either YES if there exists two non-overlapping subarrays with the same sum, or NO otherwise. The output should be written to stdout.

## sample
1
5
1 2 3 4 5
NO

</p>