magic balls

Time Limit: 3000ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 5125
64-bit integer IO format: %I64d      Java class name: Main

Description

The town of W has N people. Each person takes two magic balls A and B every day. Each ball has the volume $a_i$ and $b_i$. People often stand together. The wizard will find the longest increasing subsequence in the ball A. The wizard has M energy. Each point of energy can change the two balls’ volume.($\text{swap}(a_i, b_i)$).The wizard wants to know how to make the longest increasing subsequence and the energy is not negative in last. In order to simplify the problem, you only need to output how long the longest increasing subsequence is.

Input

The first line contains a single integer $T(1 \leq T \leq 20)$(the data for $N > 100$ less than 6 cases), indicating the number of test cases.
Each test case begins with two integer $N(1 \leq N \leq 1000)$ and $M(0 \leq M \leq 1000)$,indicating the number of people and the number of the wizard’s energy. Next N lines contains two integer $a_i$ and $b_i(1 \leq a_i, b_i \leq 10^9)$,indicating the balls’ volume.

Output

For each case, output an integer means how long the longest increasing subsequence is.

Sample Input

2
5 3
5 1
4 2
3 1
2 4
3 1
5 4
5 1
4 2
3 1
2 4
3 1

Sample Output

4
4

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .