Space Miner
InterviewTime limit2sMemory limit512 MB
Travel in straight segments through ordered 3D waypoints; for each planet, check whether any segment passes within distance ri+D of its center, then sum the resources of all planets you can reach at least once.
- Level
Medium6 of 10
- Topics
- Geometry, Implementation, Math, Simulation
- Solved
- No attempts yet
Problem
There are planets (). Each planet holds () units of resources and has radius ().
Starting from the origin , you travel in straight lines through () waypoints in the given order.
At any moment during the trip, if your distance to a planet's center is at most (), you may mine that planet with your tractor beam and collect its units of resources. You can still mine a planet when you are exactly units from its surface (that is, exactly from its center). If your path passes through a planet, that is fine — your ship can drill straight through it, which only makes mining easier. However, once a planet has been mined you cannot mine it again, even if you pass by it later.
Output the total amount of resources you can mine during the journey.
Hint: perform all calculations with 64-bit integers.
Input
The first line contains the number of planets . Each of the next lines contains five integers describing a planet: planet is located at () and has resources and radius . The next line contains the number of waypoints . Each of the next lines contains a waypoint position as three integers (). The last line contains , the maximum distance from a planet's surface at which your ship can still mine it.
Output
Output, on a single line, the total amount of resources you can mine during the journey.