#C10589. Consecutive Subsequence Sum
Consecutive Subsequence Sum
Consecutive Subsequence Sum
Given a sequence of n integers, determine if there exists a consecutive subsequence of length m whose sum is exactly s.
Formally, for a sequence \(a_1, a_2, \dots, a_n\), check if there exists an index \(i\) (with \(1 \le i \le n-m+1\)) such that
\(\sum_{j=i}^{i+m-1} a_j = s\)
You need to solve this problem efficiently. Consider using a sliding window technique to achieve an optimal solution.
inputFormat
The first line contains three space-separated integers: n
(the number of elements in the sequence), m
(the length of the subsequence), and s
(the target sum).
The second line contains n
space-separated integers representing the sequence.
outputFormat
Output a single line containing Yes
if there is a consecutive subsequence of length m
that sums to s
, otherwise output No
.
6 3 6
1 2 3 2 1 2
Yes
</p>