Ingredient Optimization

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

Hathai is proud that her catering service provides the freshest food in town. To accomplish that, she gets fresh ingredients with no preservatives delivered constantly. This brings about the challenge of preventing the ingredients from spoiling. Her current special uses exactly UU leaves of Thai basil, that need special care.

Hathai has the schedule of the deliveries of Thai basil. The ii-th delivery comes at the beginning of time M_iM\_i (in minutes since opening time), and brings exactly L_iL\_i leaves of Thai basil that can be stored for at most E_iE\_i minutes since arriving. Hathai has orders to prepare her specialty dish at times O_1,O_2,,O_NO\_1,O\_2, \dots ,O\_N. Order ii can only be fulfilled if she has UU unspoiled leaves of Thai basil at time O_iO\_i. Note that if leaves would spoil at the same time an order comes in, those leaves cannot be used to fulfill that order. If an order is fulfilled, UU of the leaves available have to be used and cannot be used for future orders. Once Hathai gets an order that she cannot fulfill, all of the remaining orders will also be canceled because she needs to close her kitchen and think about how to improve the fulfillment schedule.

For example, suppose Hathai's schedule has the following 44 deliveries:

  • Delivery time: 11. Amount: 1010. Time remaining until spoiled: 22.
  • Delivery time: 33. Amount: 44. Time remaining until spoiled: 22.
  • Delivery time: 55. Amount: 11. Time remaining until spoiled: 44.
  • Delivery time: 1010. Amount: 66. Time remaining until spoiled: 33.

And also suppose she has 44 orders placed at times 334466 and 1010. Each order requires using U=2U=2 leaves in this example.

The first delivery become spoiled at time 33, so it cannot be used on any order. Then the first order and the second order at time 33 and time 44 can be fulfilled and use up the 44 leaves from the second delivery. For the third order at time 66, there is only 11 leaf in the storage, so Hathai cannot fulfill this order. Note that although there is a delivery at time 1010, she still cannot fulfill the fourth order at time 1010 because she has already closed her kitchen. In this example, Hathai managed to fulfill 22 orders in total.

Given the delivery and order schedules, find out the maximum number of orders Hathai can fulfill if she optimizes the use of the Thai basil leaves.

입력

The first line of the input gives the number of test cases, TTTT test cases follow. Each test case starts with a line containing three integers DDNN, and UU: the number of deliveries, the number of orders and the amount of leaves needed for each order, respectively. Then, DD lines follow. The ii-th of these lines contains three integers M_iM\_iL_iL\_i, and E_iE\_i: the time of the delivery in minutes since opening time, the amount of Thai basil leaves delivered, and the number of minutes those leaves can be stored and remain fresh, respectively, of the ii-th delivery. Then, the last line contains NN integers O_1,O_2,,O_NO\_1,O\_2, \dots ,O\_N, where O_jO\_j is the time, in minutes since opening time, at which the jj-th order must be prepared.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is an integer representing the maximum number of orders Hathai can fulfill.

제한

  • 1T1001≤T≤100.
  • 1D1001≤D≤100.
  • 1N1001≤N≤100.
  • 1U1001≤U≤100.
  • 1M_i1091≤M\_i≤10^9, for all ii.
  • M_i\<M_i+1M\_i\<M\_{i+1}, for all ii. (Deliveries are given in increasing order of time.)
  • 1L_i1001≤L\_i≤100, for all ii.
  • 1O_j1091≤O\_j≤10^9, for all jj.
  • O_j\<O_j+1O\_j\<O\_{j+1}, for all jj. (Orders are given in increasing order of time.)