#K48067. Crate Division Problem

    ID: 28338 Type: Default 1000ms 256MiB

Crate Division Problem

Crate Division Problem

You are given a collection of crates, each with a specified weight. Your task is to determine if the crates can be partitioned into two groups such that the absolute difference between the total weights of the two groups is less than or equal to a given integer \(D\). In other words, let \(S\) be the sum of all weights and let \(S_1\) be the sum of one group, then the condition \(|(S - S_1) - S_1| \le D\) must hold. This problem can be solved using dynamic programming to explore the subset sum possibilities.

inputFormat

The input is read from stdin and has the following format:

T
N D
w1 w2 ... wN
... (repeated for each test case)

Where:

  • T is the number of test cases.
  • For each test case, the first line contains two integers: N (the number of crates) and D (the maximum allowed difference).
  • The next line contains N space-separated integers representing the weights of the crates.

outputFormat

For each test case, output a single line to stdout containing "YES" if the crates can be divided such that the absolute difference between the total weights of the two groups is less than or equal to \(D\); otherwise, output "NO".

## sample
1
4 3
1 2 3 4
YES

</p>