#C4191. Fruit Collection Challenge
Fruit Collection Challenge
Fruit Collection Challenge
You are given several queries. In each query, you are given a list of fruits, where each fruit has a magical property represented as a non-negative integer. Additionally, you are given two integers \(n\) and \(m\), where \(n\) is the total number of fruits available and \(m\) is the exact number of fruits you must collect. You are also provided with a target integer \(T\). Your task is to determine whether it is possible to choose exactly \(m\) fruits from the given \(n\) fruits such that the sum of their magical properties is exactly \(T\).
Formally, for every query, you need to decide if there exists a subset \(S\) of fruits with \(|S|=m\) and
[ \sum_{x \in S} x = T. ]
If such a subset exists, print YES
; otherwise, print NO
for that query.
inputFormat
The first line of input contains a single integer \(q\) representing the number of queries. Each query is given in the following format:
- A line with two integers \(n\) and \(m\), where \(n\) is the number of fruits and \(m\) is the number of fruits to select.
- A line with \(n\) non-negative integers representing the magical properties of the fruits.
- A line with an integer \(T\), the target sum.
All queries are concatenated one after the other.
outputFormat
For each query, output a single line that contains either YES
if it is possible to collect exactly \(m\) fruits whose magical properties sum up to \(T\), or NO
if it is not possible.
1
5 3
10 20 30 40 50
60
YES