TV Series

Time limit: 0.1s Memory limit: 256MB Input: Output:

Alessandro is a big fan of TV series and is eager to discuss them with his friends. In the next DD days, they will be talking about NN different series, numbered from 00 to N1N − 1, with series ii being discussed from day SiS_i to day EiE_i included. Note that time passes fast when having fun, thus in a single day they will discuss at most one series.

Alessandro has not watched any of those series yet, but he wants to talk with his friends as much as possible. However he only has a limited amount of free time and knows it will take him XiX_i days to watch series ii. Alessandro can watch the series in any order and skip some, but he cannot start watching a new series before finishing the previous one. In order to take part in the discussion on day dd, Alessandro must have watched completely the tv series which is being talked about by the end of day d1d − 1.

For how many days, at most, can he take part in the discussion with his friends?

Input data

The input file consists of:

  • a line containing integers N,DN, D: the number of TV series that will be discussed and the number of days.
  • a line containing the NN integers S0,...,SN1S_0, . . . , S_{N−1}.
  • a line containing the NN integers E0,...,EN1E_0, . . . , E_{N−1}.
  • a line containing the NN integers X0,...,XN1X_0, . . . , X_{N−1}.

Output data

The output file must contain a single line consisting of integer KK, the maximum number of days in which Alessandro can discuss TV series with his friends.

Constraints and clarifications

  • 1N2 0001 \leq N \leq 2 \ 000.
  • 1D5 0001 \leq D \leq 5 \ 000.
  • 1Si,Ei,XiD1 \leq S_i, E_i, X_i \leq D for each i=0,1,...N1i = 0, 1, . . . N − 1.
  • SiEiSi+1Si \leq E_i \leq S_{i+1} for each i=0,1,...N2i = 0, 1, . . . N − 2.
# Points Constraints
1 0 Examples
2 18 N18,D100N \leq 18, D \leq 100
3 25 N100,D100N \leq 100, D \leq 100
4 57 No additional limitations

Your program will be tested against several test cases grouped in subtasks. In order to obtain the score of a subtask, your program needs to correctly solve all of its test cases.

Example 1

stdin

2 4
2 4
2 4
1 2

stdout

2

Explanation

In the first sample case there are 22 TV series and 44 days.

  • Series 00 will be discussed on day 22 and takes 11 day to watch.
  • Series 11 will be discussed on days 33 and 44 and takes 22 days to watch.

It is optimal for Alessandro to watch series 11 on day 11 and discuss it on day 22, then watch series 22 on days 22 and 33 and discuss it on day 44. This will let Alessandro take part in both days of discussion.

Example 2

stdin

4 10
2 3 7 8
2 6 7 10
1 4 3 2

stdout

5

Explanation

In the second sample case there are 44 TV series and 1010 days.

  • Series 00 will be discussed on day 22 and takes 11 day to watch.
  • Series 11 will be discussed on days 3,4,53, 4, 5 and 66 and takes 44 days to watch.
  • Series 22 will be discussed on day 77 and takes 33 days to watch.
  • Series 33 will be discussed on days 8,98, 9 and 1010 and takes 22 days to watch.

It is optimal for Alessandro to watch series 11 on days 1,2,31, 2, 3 and 44, and discuss it on days 55 and 66 and to watch series 33 on days 66 and 77, then discuss it on days 8,98, 9 and 1010. This will let Alessandro participate to the discussion on 55 days, and it can be proven that he cannot do better.

Log in or sign up to be able to send submissions!