Bon Appetit

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer.
Each customer that visits the restaurant has a strongly preferred compartment p (1 ≤ p ≤ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this.
Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant.
Input
The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers s_{i}, f_{i} and p_{i} , the arrival time, departure time and the strongly preferred compartment of the i^{th} customer respectively.
Note that the i^{th} customer wants to occupy the p_{i}^{th} compartment from [s_{i}, f_{i}) i.e the i^{th} customer leaves just before f_{i} so that another customer can occupy that compartment from f_{i} onwards.
Output
For every test case, print in a single line the maximum number of customers that dine at the restaurant.
Constraints
 1 ≤ T ≤ 30
 0 ≤ N ≤ 10^{5}
 1 ≤ K ≤ 10^{9}
 0 ≤ s_{i} < f_{i} ≤ 10^{9}
 1 ≤ p_{i} ≤ K
Example
Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3
Explanation
Example case 1.
All three customers want different compartments and hence all 3 can be accommodated.
Example case 2.
If we serve the 1^{st}, 2^{nd} and 4^{th} customers, then we can get a maximum of 3.
Author:  viv001 
Tester:  gerald 
Editorial  http://discuss.codechef.com/problems/FGFS 
Tags  easy, greedy, jan14, sorting, viv001 
Date Added:  7122013 
Time Limit:  0.5 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 