#P8083. [COCI 2011/2012 #4] OGRADA
[COCI 2011/2012 #4] OGRADA
Problem Description
You are given two arrays , each with elements.
Define the weight of an array as the sum of the absolute differences of all adjacent elements in the array. You may reorder array into any permutation , such that for all :
- If , then .
- If , then .
Find, among all valid permutations, a permutation with the maximum weight, and output this maximum weight.
Input Format
The first line contains an integer .
The second line contains positive integers .
The third line contains positive integers .
Output Format
The first line contains one positive integer, the maximum weight.
The second line contains positive integers separated by spaces, representing the elements of . If there are multiple valid , output any one of them.
4
5 7 4 9
1 2 3 4
7
2 4 1 3
10
9 5 1 2 6 7 4 18 20 12
10 40 20 30 50 70 80 100 1000 500
3010
100 80 10 40 50 1000 20 70 500 30
Hint
[Sample 1 Explanation]
Valid arrays include:
- , with weight .
- , with weight .
- , with weight .
- , with weight .
- , with weight .
[Constraints]
- For of the testdata, , and .
[Hints and Notes]
If you only get the first line correct but the second line is wrong or empty, you can get of the score for the corresponding test point.
You are welcome to hack the self-written Special Judge via private messages or by making a post.
This problem is translated from COCI 2011-2012 CONTEST #4 Task 4 OGRADA.
The score of this problem follows the original COCI setting, with a full score of .
Translated by ChatGPT 5