Under construction

Still being built. Things may change

Reality Show

Time limit2sMemory limit1024 MB

Summary
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. nn candidates numbered from 11 to nn have been interviewed. Candidate ii has aggressiveness level lil_i, and recruiting this candidate costs the show sis_i roubles.

The host reviews the applications from i=1i=1 to i=ni=n in index order and decides whether to recruit each candidate. If the aggressiveness level of candidate ii is strictly higher than that of every already accepted candidate, candidate ii 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 vv, a profitability value cvc_v is given, which can be positive or negative. All recruited participants enter the stage one by one in index order. When participant ii enters the stage, the following happens.

  • The show earns clic_{l_i} roubles, where lil_i is the initial aggressiveness level of participant ii.
  • 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 ctc_t roubles, where tt 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 sis_i). Help the host make the show as profitable as possible.

Input

The first line contains two integers nn and mm (1≤n,m≤20001 \le n, m \le 2000), the number of candidates and an upper bound for the initial aggressiveness levels.

The second line contains nn integers lil_i (1≤li≤m1 \le l_i \le m), the initial aggressiveness levels of all candidates.

The third line contains nn integers sis_i (0≤si≤50000 \le s_i \le 5000), the cost in roubles to recruit each candidate.

The fourth line contains n+mn + m integers cic_i (∣ci∣≤5000|c_i| \le 5000), the profitability for each aggressiveness level.

It is guaranteed that the aggressiveness level of any participant never exceeds n+mn + m 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 11, 22, 33, and 55. Then the show pays 1+2+1+1=51 + 2 + 1 + 1 = 5 roubles in recruitment. The events on stage proceed as follows.

  • A participant with aggressiveness level 44 enters, and the show makes 44 roubles.
  • A participant with aggressiveness level 33 enters, and the show makes 33 roubles.
  • A participant with aggressiveness level 11 enters, and the show makes 11 rouble.
  • Another participant with aggressiveness level 11 enters, and the show makes 11 rouble. A fight starts. One participant leaves, and the other rises to level 22, which earns the show an extra 22 roubles.

Total revenue is 4+3+1+1+2=114 + 3 + 1 + 1 + 2 = 11 roubles, so the profit is 11−5=611 - 5 = 6 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 11.

Examples3

  1. Example 1

    Input
    5 4
    4 3 1 2 1
    1 2 1 2 1
    1 2 3 4 5 6 7 8 9
    
    Expected output
    6
    
  2. Example 2

    Input
    2 2
    1 2
    0 0
    2 1 -100 -100
    
    Expected output
    2
    
  3. Example 3

    Input
    5 4
    4 3 2 1 1
    0 2 6 7 4
    12 12 12 6 -3 -5 3 10 -4
    
    Expected output
    62