Gangsters

Time limit1sMemory limit128 MB

Summary
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

NN gangsters are going to a restaurant. The ii-th gangster arrives at time TiT_i and has prosperity PiP_i. The restaurant door has K+1K+1 states of openness, represented by the integers in the range [0,K][0, K]. The state of openness can change by at most 11 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 00).

The ii-th gangster enters the restaurant only if the door is opened specially for him, i.e. when the state of openness equals his stoutness SiS_i exactly. If, at the moment the gangster arrives, the state of openness is not equal to his SiS_i, the gangster leaves and never returns.

The restaurant operates during the time interval [0,T][0, T].

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 NN, KK, and TT, separated by spaces. (1≤N≤1001 \le N \le 100, 1≤K≤1001 \le K \le 100, 0≤T≤30,0000 \le T \le 30{,}000)

The second line contains the arrival times T1,T2,…,TNT_1, T_2, \dots, T_N, separated by spaces. (0≤Ti≤T0 \le T_i \le T for i=1,2,…,Ni = 1, 2, \dots, N)

The third line contains the prosperities P1,P2,…,PNP_1, P_2, \dots, P_N, separated by spaces. (0≤Pi≤3000 \le P_i \le 300 for i=1,2,…,Ni = 1, 2, \dots, N)

The fourth line contains the stoutnesses S1,S2,…,SNS_1, S_2, \dots, S_N, separated by spaces. (1≤Si≤K1 \le S_i \le K for i=1,2,…,Ni = 1, 2, \dots, N)

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 00.

Examples3

  1. Example 1

    Input
    4 10 20
    10 16 8 16
    10 11 15 1
    10 7 1 8
    
    Expected output
    26
    
  2. Example 2

    Input
    1 5 10
    5
    42
    3
    
    Expected output
    42
    
  3. Example 3

    Input
    2 5 5
    3 3
    10 20
    2 2
    
    Expected output
    30