Gangsters
Time limit1sMemory limit128 MB
Choose a door state over time that changes by at most 1 per unit, starting at 0, to maximize the prosperity of gangsters whose stoutness matches the state at their arrival time.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sorting, Implementation
- Solved
- No attempts yet
Problem
gangsters are going to a restaurant. The -th gangster arrives at time and has prosperity . The restaurant door has states of openness, represented by the integers in the range . The state of openness can change by at most per unit of time; that is, it either opens by one, closes by one, or stays the same. At the initial moment the door is closed (state ).
The -th gangster enters the restaurant only if the door is opened specially for him, i.e. when the state of openness equals his stoutness exactly. If, at the moment the gangster arrives, the state of openness is not equal to his , the gangster leaves and never returns.
The restaurant operates during the time interval .
The goal is to open and close the door appropriately so that the total prosperity of the gangsters gathered in the restaurant is maximized.
Input
The first line contains three integers , , and , separated by spaces. (, , )
The second line contains the arrival times , separated by spaces. ( for )
The third line contains the prosperities , separated by spaces. ( for )
The fourth line contains the stoutnesses , separated by spaces. ( for )
All values in the input are integers.
Output
Print a single integer — the maximal total prosperity of the gangsters gathered in the restaurant. If no gangster can enter the restaurant, print .