#P17167. [CEOI 2026] Towers
[CEOI 2026] Towers
Problem Description
You have computers and towers all at distinct positions along a line. You need to pair computers using cables in such a way that every cable starts at some computer, visits some towers and ends at another computer. The cable can visit any of the towers (not just the ones between the computers) in an arbitrary order. It can skip towers by passing by without visiting them. It can also visit no towers at all and connect the two computers directly but it cannot connect a computer to itself. The number of computers is even.
Let and be the positions of two computers and let be positions of the towers the cable visits. The length of the cable is . For some cable we define its score as , where is its length, is some fixed constant and is the number of unique towers the cable visits among . Multiple cables can visit the same tower and that tower contributes to the score of each of those cables.
You need to compute the maximum possible sum of cable scores for pairing up all computers (i.e. each computer has to belong to exactly one pair, or equivalently, it must be connected to exactly one cable).
Input Format
The first line contains the number of test cases, . The test cases follow one after another. Each test case consists of three lines. The first line contains three integers , and - the number of computers, the number of towers and the constant . The second line contains integers - the positions of computers. The third line contains integers - the positions of towers.
Output Format
Output integers, each on its own line - the maximum possible sum of scores of cables for each test case.
4
2 1 100
1 10
11
4 1 10
2 4 6 8
20
4 1 10
2 4 6 8
5
6 3 10
2 13 4 8 6 10
5 1 9
89
-4
12
51
Hint
Constraints
Let and be the sum of and through all test cases, respectively.
- is even
- All positions of computers and towers are unique (within an individual test case).
Subtasks
- Subtask ( points): ,
- Subtask ( points): , ,
- Subtask ( points):
- Subtask ( points):
- Subtask ( points): No additional constraints.