#T243. 开餐馆
开餐馆
Description
Xiao Ming, a student from the School of Information, plans to start a restaurant business after graduation. There are currently locations to choose from, and Xiao Ming intends to select suitable spots to open some restaurants.
These locations are arranged in a straight line. Their relative positions are represented by an integer sequence .
Due to varying地段 (location) factors, the profits from opening restaurants differ. We use to denote the profit from opening a restaurant at . To avoid internal competition among his restaurants, the distance between any two restaurants must be greater than . Please help Xiao Ming select a plan that maximizes the total profit.
Input Format
The first line of input is an integer (), indicating there are test cases. This is followed by consecutive test cases. Each test case consists of lines:
- Line 1: The total number of locations () and the distance restriction ( and );
- Line 2: The positions of the locations ( and integers, listed in ascending order);
- Line 3: The profits of opening restaurants at the locations ( and integers).
Output Format
For each test case, output the maximum possible profit.
2
3 11
1 2 15
10 2 30
3 16
1 2 15
10 2 30
40
30