#C6852. Exact Weight Subset
Exact Weight Subset
Exact Weight Subset
You are given a set of boxes with specific weights. Your task is to determine whether there exists a subset of these boxes whose total weight is exactly equal to a given target \(W\). This is a classic subset-sum problem that can be solved using a dynamic programming approach.
Formally, given \(N\) boxes with weights \(w_1, w_2, \ldots, w_N\) and a target weight \(W\), decide if there exists a subset \(S \subseteq \{1, 2, \ldots, N\}\) such that \[ \sum_{i \in S} w_i = W. \]
If such a subset exists, output YES; otherwise, output NO.
inputFormat
The input is provided via standard input (stdin) and consists of three lines:
- The first line contains a single integer \(N\), representing the number of boxes.
- The second line contains \(N\) space-separated integers representing the weights of the boxes.
- The third line contains a single integer \(W\), the target weight.
outputFormat
Output a single line to standard output (stdout): YES if there exists a subset of boxes whose weights sum exactly to \(W\); otherwise, output NO.
## sample5
2 3 7 8 10
11
YES