#t413. 开餐馆

开餐馆

Opening a Restaurant

Problem Description

Xiaoming, a graduate of the School of Information, plans to start a business opening restaurants. There are nn candidate locations. Xiaoming wants to choose suitable locations to open some restaurants. The nn locations lie on a straight line. We use an integer sequence m1,m2,…,mnm_1,m_2,\dots,m_n to represent their relative positions. Because of location, the profit of opening a restaurant differs. We use pip_i to denote the profit of opening a restaurant at mim_i. To avoid internal competition among his own restaurants, the distance between any two restaurants must be greater than kk. Please help Xiaoming choose a plan that maximizes the total profit.

Input Format

The first line of input is an integer T (1≤T≤1000)T\ (1\le T\le 1000), indicating there are TT test cases. The following TT test cases are given consecutively. Each test case has 33 lines.

Line 1: total number of locations n (n<100)n\ (n<100), and distance limit k (k>0k\ (k>0 and k<1000)k<1000).

Line 2: the positions m1,m2,…,mnm_1,m_2,\dots,m_n of the nn locations (1000000>mi>01000000>m_i>0, integers, in ascending order).

Line 3: the restaurant profits p1,p2,…,pnp_1,p_2,\dots,p_n at the nn locations (1000>pi>01000>p_i>0, integers).

Output Format

For each test case, output the maximum possible profit.

Sample Input 1

2
3 11
1 2 15
10 2 30
3 16
1 2 15
10 2 30

Sample Output 1

40
30

Constraints

1≤T≤10001\le T\le 1000; n<100n<100; 0<k<10000<k<1000; 1000000>mi>01000000>m_i>0; 1000>pi>01000>p_i>0.

Source: "一本通在线评测" (Yiben Tong Online Judge).