You are given a sequence of distinct integers and a set of allowed differences. Your task is to find the length of the longest increasing subsequence in which the difference between any two adjacent elements is one of the allowed differences. For example, if the allowed differences are $$$1$$$ and $$$3$$$, then the subsequence $$$1, 4, 5, 8$$$ will satisfy the condition, while the sequence $$$1, 2, 4$$$ will not, as the difference between the second and third element is $$$2$$$.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^6$$$ and $$$1 \le k \le 10$$$): the number of elements in the sequence and the number of allowed differences, respectively. The second line contains $$$n$$$ distinct integers $$$s_i$$$ ($$$1 \le s_i \le 10^9$$$): the elements of the sequence. The third line contains $$$k$$$ distinct integers $$$d_i$$$ ($$$1 \le d_i \le 10^9$$$): the allowed differences.
One positive integer: the length of the longest increasing subsequence with allowed differences.
7 22 5 6 3 8 10 93 1
4
9 22 5 6 3 8 10 9 7 121 3
5
| Name |
|---|


