Venus Rover
InterviewTime limit1sMemory limit128 MB
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 , , and . Here is the number of stones found, is the time available before the rocket returns to collect Greedy and the container, and is the maximum mass of stones the rocket can lift.
- Then lines follow; the -th line contains three positive integers , , and (all at most ), giving respectively the time required to pick up stone , 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.