#C945. Contiguous Subarray Sum as a Perfect Square
Contiguous Subarray Sum as a Perfect Square
Contiguous Subarray Sum as a Perfect Square
Given an array of non-negative integers, your task is to determine whether there exists a contiguous subarray whose sum is a perfect square. In mathematical terms, a number S is a perfect square if there exists an integer k such that S = \(k^2\). For example, if the array is [1, 3, 4, 1, 5], one of its contiguous subarrays may have a sum that satisfies this property.
If such a subarray exists, output YES
; otherwise, output NO
.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer \(n\), the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
Output a single line to standard output (stdout) containing YES
if there exists a contiguous subarray whose sum is a perfect square, and NO
otherwise.
5
1 3 4 1 5
YES
</p>