Swapping Pairs

5

1 votes
Problem

You are given \(N\) pairs \((A_{1}, B_{1}),\ (A_{2}, B_{2}),\ ...,\ (A_{N}, B_{N})\). You are also given an integer \(M\).

You can swap any pair, that is, for the \(i^{th}\) pair, \(A_{i}\) becomes \(B_{i}\) and \(B_{i}\) becomes \(A_{i}\). You have to apply this operation in such a way that, 

\(\sum_{i=1}^{N} A_i = M\)

Your task is to determine whether the conditions can be satisfied or not. If the condition can be satisfied, then print \(YES\), otherwise print \(NO\).

Input Format

  • The first line contains an integer \(T\) denoting the number of test cases. Description of each test case is as follows:
  • The first line of each test case contains two space-seperated integers \(N\) and \(M\).
  • The next \(N\) lines contains two space-seperated integers \(A_{i}\) and \(B_{i}\) denoting the \(i^{th}\) pair.

Output Format

For each test case, print \(YES\), if it is possible to satisfy the given condition, otherwise print \(NO\).

Constraints

\(1 \le T \le 100\)

\(1 \le N \le 1000\)

\(1 \le M \le 10000\)

\(1 \le A_{i}, \ B_{i} \le 1000\)

It is guaranteed that the sum of values of \(N\) over all test cases in the input does not exceed \(1000\).

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

In the first test case, you can swap the \(2^{nd}\) pair. Thus, the sum will be \(4 + 1 = 5\).

In the second test case, we can show that there is no possible way to satisfy the condition.

In the third test case, there are multiple ways of satisfying the condition. One of the possible ways is to swap the 2nd and 4th pairs.

Editor Image

?