This page is still under construction.

Parts of this page are still being built. What you see may change.

Venus Rover

Interview

Time limit1sMemory limit128 MB

Summary
Choose which stones to collect so total value is maximized, given limits on time and total lifted mass.
Level

Medium5 of 10

Topics
Dynamic programming
Solved
No attempts yet

Problem

After NASA sent its Mars exploration rovers Spirit and Opportunity to Mars, ASAN decided to send its Venus exploration rover Greedy to Venus to find out which valuable raw resources can be obtained there. Greedy's mission is to collect stones from the surface of Venus.

Greedy is carried to Venus by a rocket. The rocket drops Greedy onto the surface together with a large container, flies seven times around Venus, and finally picks up both Greedy and the container with its on-board grabbers.

After landing, Greedy uses its IntelliSensor technology to scan for every interesting stone within half a mile. This produces a list of stones, each with an accurate estimate of its mass, its value, and the time needed to pick it up and place it in the container. The container is large enough to hold all of the stones, but the rocket can lift only a limited amount of mass from the surface. The available time is also limited, because the rocket returns after its seven laps around Venus.

Your task is to write a program that decides which stones to pick up and place in the container so that the total value is maximized.

Input

The first line contains the number of test cases. Each test case has the following format.

  • A line with three positive integers NN, TT, and MM. Here 0<N≤1000 < N \le 100 is the number of stones found, 0<T≤1000 < T \le 100 is the time available before the rocket returns to collect Greedy and the container, and 0<M≤1000 < M \le 100 is the maximum mass of stones the rocket can lift.
  • Then NN lines follow; the ii-th line contains three positive integers tit_i, mim_i, and viv_i (all at most 10610^6), giving respectively the time required to pick up stone ii, its estimated mass, and its estimated value.

Output

For each test case, print on a single line a single integer: the maximum total value that can be collected in that test case.

Examples4

  1. Example 1

    Input
    2
    1 20 10
    2 2 100
    5 20 10
    6 6 10
    10 5 12
    5 10 18
    12 5 10
    3 3 7
    
    Expected output
    100
    19
    
  2. Example 2

    Input
    1
    1 5 5
    5 5 50
    
    Expected output
    50
    
  3. Example 3

    Input
    1
    1 100 1
    1 2 100
    
    Expected output
    0
    
  4. Example 4

    Input
    1
    1 1 100
    2 1 100
    
    Expected output
    0