Bounty Hunter
Time limit4sMemory limit1024 MB
Muji starts at the origin and moves along the axes while thieves travel in fixed directions. Find the maximum total bounty Muji can collect within T hours.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sorting, Geometry
- Solved
- No attempts yet
Problem
N thieves escaped into an infinitely large two-dimensional plane.
Bounty hunter Muji has T time left and wants to catch as many thieves as possible to collect the bounties on them.
Each thief starts at an integer coordinate point and moves at speed 1 for one hour in only one initial direction, chosen from east, south, west, or north.
Muji moves at the same speed as a thief, but can change to any of the four directions at any time. Muji may also stay in place.
The X coordinate increases toward the east, and the Y coordinate increases toward the north.
If Muji and a thief are at the same position at the same time, Muji spends 1 hour to catch that thief at that position and earns the bounty . Muji cannot catch two or more thieves at once. The position may have real-valued coordinates.
Muji starts at the origin (0,0). Find the maximum total bounty Muji can earn within the remaining time T.
Input
The first line contains the number of thieves and the remaining time , separated by a space. (, )
From the second line through line , each line contains the thief's initial position , , bounty , and direction , separated by spaces. (, , , )
The thief moves east if is 0, south if 1, west if 2, and north if 3.
Output
Print the maximum total bounty Muji can collect by catching thieves within the remaining time .
Hint
Muji always moves parallel to the axis or the axis.