It Can Be Arranged
Time limit2sMemory limit128 MB
Find the fewest rooms for daily courses that each need several parallel rooms, where a room can run course j after course i only if cleaning ends first.
Problem
Every year several universities host national programming contests. Dhaka holds an ICPC regional contest every year, and one or two teams from it go to the ICPC World Finals.
After watching those contests, MMR (Mission Maker Rahman) decided to open a programming school. The school teaches courses, and every course meets every day, because a programmer must not forget dynamic programming while learning computational geometry. Course starts at time and finishes at time , and both endpoints count as class time. Course has registered students, and no student is registered for two courses.
MMR wants to hire rooms in a building called Sentinel Tower. One room holds at most students, so course occupies rooms at the same time and runs the same class separately in each of them.
Programmers are restless and they leave a mess. Once course finishes in a room, cleaning that room before course starts there takes time. So course can follow course directly in the same room only when .
Every course repeats at the same time each day, so you plan a single day. Find the minimum number of rooms MMR has to hire.
Input
The first line has the number of test cases . ()
The first line of each test case has the number of courses and the capacity of one room . (, )
Each of the next lines has the start time , the finish time , and the number of registered students of course . (, )
Each of the next lines has one row of the cleaning time matrix. The -th integer of the -th row is . (, )
Output
For each test case print one line in the form Case x: y, where is the test case number starting from 1 and is the minimum number of rooms to hire.