#P16447. [XJTUPC 2026] ADOIAF
[XJTUPC 2026] ADOIAF
Problem Description
ShwStone is playing a game called A Dance Of Ice And Fire (ADOIAF). It is a one-button rhythm game. ShwStone needs to press the key at the correct time. However, ShwStone is not very good, and often loses points because the timing is off. ShwStone wants to know: if all judgments could be matched in the way he wants, what is the maximum score he can get.
Formally, ADOIAF has judgment points . ShwStone presses the key times, and the press time sequence is . ADOIAF has a built-in judgment parameter . If we choose to match the -th key press with the -th judgment point, the score gained is .
Note that in the final plan, each key press can satisfy at most one judgment point, and each judgment point can be satisfied at most once. There is no ordering requirement between matched key presses and judgment points.
You need to output the maximum total score.
Input Format
This problem contains multiple test cases. The first line contains a positive integer (), representing the number of test cases.
Next are test cases.
For each test case, the first line contains three positive integers , , and (, ), separated by spaces, representing the number of judgment points, the number of key presses, and the judgment parameter.
The next line contains positive integers (), separated by spaces, representing the time sequence of the judgment points. It is guaranteed that all are distinct. The input is not guaranteed to be sorted.
The next line contains positive integers (), separated by spaces, representing the time sequence of key presses. It is guaranteed that all are distinct. The input is not guaranteed to be sorted.
It is guaranteed that across all test cases, the sum of does not exceed , and the sum of does not exceed .
Output Format
For each test case, output one line containing a non-negative integer, representing the maximum score ShwStone can obtain under an optimal matching.
2
7 7 3
5 4 14 8 1 17 6
6 13 3 12 15 14 10
8 8 4
9 6 14 11 12 5 2 13
14 7 15 5 20 12 11 9
36
109
Hint
Translated by ChatGPT 5