Building Heights

With building 1 at height 0, adjacent heights differing by at most K, and M caps, find the maximum achievable height of any building.

Medium6GreedyImplementationMathPrefix sumNo attempts yetTime limit2sMemory limit512 MB

Problem

You put up NN new buildings in a row. Number them 1 to NN from the left.

The heights obey these limits.

  • Every building height is a non-negative integer.
  • Building 1 has height 0.
  • Two neighboring buildings differ in height by at most KK.
  • Building XiX_i has height at most TiT_i.

Write a program that finds the height of the tallest building you can put up while every limit holds.

Input

The first line contains NN and KK. (1N,K1091 \le N, K \le 10^9)

The second line contains MM, the number of buildings that carry a height cap. (0Mmin(N,500)0 \le M \le \min(N, 500))

If MM is at least 1, the third line contains X1,X2,,XMX_1, X_2, \dots, X_M and the fourth line contains T1,T2,,TMT_1, T_2, \dots, T_M, separated by spaces. (1XiN1 \le X_i \le N, 1Ti1091 \le T_i \le 10^9, Xi<Xi+1X_i < X_{i+1}) If MM is 0, the third and fourth lines are not given.

Output

Print the height of the tallest building you can put up while every limit holds.