#C1777. Color Combination Sum

    ID: 45019 Type: Default 1000ms 256MiB

Color Combination Sum

Color Combination Sum

You are given a list of basic colors, each represented as an RGB tuple, and a target color (also an RGB tuple). Your task is to determine if the target color can be obtained by taking a non‐empty subset of the basic colors and combining them using saturated addition. The saturated addition for each color channel is defined as follows:

\[ S = \min(c_1 + c_2, 255) \]

For a subset of colors, the resulting color is obtained by applying the above addition channel‐wise. If the resulting RGB tuple exactly matches the target color, output Yes; otherwise, output No.

Note: At least one basic color must be chosen and each basic color can be used at most once in the sum.

inputFormat

The first line of input contains an integer T representing the number of test cases. For each test case:

  • The first line contains an integer n (the number of basic colors).
  • The next n lines each contain three space-separated integers, representing the RGB values of a basic color.
  • The next line contains three space-separated integers representing the target color's RGB values.

All input is provided via standard input.

outputFormat

For each test case, print a single line with either Yes if the target color can be formed from the basic colors using the described saturated addition, or No otherwise. Output is written to standard output.

## sample
2
3
255 0 0
0 255 0
0 0 255
255 255 255
2
100 150 200
50 100 50
100 150 250
Yes

No

</p>