Reality Show
Time limit2sMemory limit1024 MB
Pick a subset of candidates that obeys the record rule, then maximize the on-stage fight revenue minus the recruitment costs.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Bit manipulation
- Solved
- No attempts yet
Problem
A popular reality show is recruiting a new cast for its third season. candidates numbered from to have been interviewed. Candidate has aggressiveness level , and recruiting this candidate costs the show roubles.
The host reviews the applications from to in index order and decides whether to recruit each candidate. If the aggressiveness level of candidate is strictly higher than that of every already accepted candidate, candidate is rejected automatically. Otherwise, the host may accept or reject the candidate as she wishes. The host wants to choose the cast that maximizes the total profit.
The show earns revenue as follows. For each aggressiveness level , a profitability value is given, which can be positive or negative. All recruited participants enter the stage one by one in index order. When participant enters the stage, the following happens.
- The show earns roubles, where is the initial aggressiveness level of participant .
- If two participants on stage have the same aggressiveness level, they fight immediately. The defeated participant is hospitalized and leaves the show. The victor's aggressiveness level increases by one, and the show earns roubles, where is the new level.
- Fights continue until all participants on stage have distinct aggressiveness levels.
The host wants to recruit the cast that maximizes total profit. Profit is the total revenue from events on stage minus the total recruitment cost (the sum of all accepted ). Help the host make the show as profitable as possible.
Input
The first line contains two integers and (), the number of candidates and an upper bound for the initial aggressiveness levels.
The second line contains integers (), the initial aggressiveness levels of all candidates.
The third line contains integers (), the cost in roubles to recruit each candidate.
The fourth line contains integers (), the profitability for each aggressiveness level.
It is guaranteed that the aggressiveness level of any participant never exceeds under the given conditions.
Output
Print a single integer, the largest profit the show can make.
Hint
In the first sample, it is optimal to recruit candidates , , , and . Then the show pays roubles in recruitment. The events on stage proceed as follows.
- A participant with aggressiveness level enters, and the show makes roubles.
- A participant with aggressiveness level enters, and the show makes roubles.
- A participant with aggressiveness level enters, and the show makes rouble.
- Another participant with aggressiveness level enters, and the show makes rouble. A fight starts. One participant leaves, and the other rises to level , which earns the show an extra roubles.
Total revenue is roubles, so the profit is roubles.
In the second sample, the show cannot recruit both candidates because the second one has a higher aggressiveness level. It is better to recruit only candidate .