#C4468. Subarray Sum Query
Subarray Sum Query
Subarray Sum Query
You are given an array of n integers and q queries. For each query, you are given two integers m and k. Your task is to determine whether there exists any contiguous subarray of exactly length m whose elements sum up exactly to k.
Note: If m is greater than n (the length of the array), the answer for that query is automatically NO
.
Example: Consider the array [1, 2, 3, 4, 5] with a query (2, 9). The subarray [4, 5] has a sum of 9, so the answer is YES
.
inputFormat
The input is read from standard input (stdin
) and has the following format:
n A1 A2 ... An q m1 k1 ... mq kq
Where:
n
is the number of elements in the array.- The second line contains
n
space-separated integers representing the arrayA
. q
is the number of queries.- Each of the next
q
lines contains two integers,m
andk
, representing a query.
outputFormat
For each query, output a single line to standard output (stdout
) with the string YES
if there exists a contiguous subarray of length exactly m
whose sum is k
, or NO
otherwise.
5
1 2 3 4 5
2
2 9
3 6
YES
YES
</p>