#K91392. Sublist Sum Finder
Sublist Sum Finder
Sublist Sum Finder
You are given a list of n positive integers representing the number of pages in books and a target integer p. Your task is to determine whether there exists a contiguous sublist (also known as a subarray) whose sum is exactly p.
Mathematically, you need to check whether there exist indices \( i \) and \( j \) (with \( 0 \le i \le j < n \)) such that:
[ \sum_{k=i}^{j} pages[k] = p ]
If such a sublist exists, output YES
; otherwise, output NO
.
Note: It is guaranteed that all page counts are positive integers.
inputFormat
The first line contains two integers n
and p
where n
is the number of books and p
is the target sum.
The second line contains n
space-separated positive integers representing the page counts of the books.
outputFormat
Output a single line with YES
if there exists a contiguous sublist whose sum is exactly p
, otherwise output NO
.
5 15
1 2 3 4 5
YES