#K50192. Borrowing Books Challenge
Borrowing Books Challenge
Borrowing Books Challenge
You are given n books, each with a certain number of pages. Your task is to determine if it is possible to select a non-empty subset of these books such that the sum of their pages is exactly equal to a given number p.
Formally, given a list of integers \(a_1, a_2, \ldots, a_n\) representing the number of pages in each book, decide whether there exists a subset \(S\) (with \(S \neq \emptyset\)) such that:
[ \sum_{i \in S} a_i = p ]
If such a subset exists, print YES
; otherwise, print NO
.
inputFormat
The input is given via standard input (stdin) and has the following format:
- The first line contains an integer t, the number of test cases.
- For each test case:
- A line containing two integers n and p, where n is the number of books and p is the required total number of pages.
- A line containing n space-separated integers representing the page counts of each book.
outputFormat
For each test case, output a single line to standard output (stdout) containing either YES
or NO
, depending on whether it is possible to select a non-empty subset of books whose page counts sum exactly to p.
3
5 8
2 3 5 2 1
4 10
2 2 2 2
3 6
1 2 3
YES
NO
YES
</p>