#P16447. [XJTUPC 2026] ADOIAF

    ID: 18478 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>动态规划 DP四边形不等式2026高校校赛

[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 nn judgment points ta1,ta2,,tant_{a_1}, t_{a_2}, \cdots, t_{a_n}. ShwStone presses the key mm times, and the press time sequence is tb1,tb2,,tbmt_{b_1}, t_{b_2}, \cdots, t_{b_m}. ADOIAF has a built-in judgment parameter kk. If we choose to match the jj-th key press with the ii-th judgment point, the score gained is max(k2(taitbj)2,0)\max(k^2 - (t_{a_i} - t_{b_j})^2, 0).

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 TT (1T1041 \le T \le 10^4), representing the number of test cases.

Next are TT test cases.

For each test case, the first line contains three positive integers nn, mm, and kk (1n,m1051 \le n, m \le 10^5, 1k501 \le k \le 50), separated by spaces, representing the number of judgment points, the number of key presses, and the judgment parameter.

The next line contains nn positive integers ta1,ta2,,tant_{a_1}, t_{a_2}, \cdots, t_{a_n} (1tai1061 \le t_{a_i} \le 10^6), separated by spaces, representing the time sequence of the judgment points. It is guaranteed that all tait_{a_i} are distinct. The input is not guaranteed to be sorted.

The next line contains mm positive integers tb1,tb2,,tbmt_{b_1}, t_{b_2}, \cdots, t_{b_m} (1tbj1061 \le t_{b_j} \le 10^6), separated by spaces, representing the time sequence of key presses. It is guaranteed that all tbjt_{b_j} are distinct. The input is not guaranteed to be sorted.

It is guaranteed that across all test cases, the sum of nn does not exceed 10510^5, and the sum of mm does not exceed 10510^5.

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