#C6852. Exact Weight Subset

    ID: 50658 Type: Default 1000ms 256MiB

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:

  1. The first line contains a single integer \(N\), representing the number of boxes.
  2. The second line contains \(N\) space-separated integers representing the weights of the boxes.
  3. 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.

## sample
5
2 3 7 8 10
11
YES