#P8920. 『MdOI R5』Variance
『MdOI R5』Variance
Background
Subtasks 1 to 5 use the original testdata, and Subtask 6 uses hack testdata.
Problem Description
Given two integer sequences of length , satisfying:
- $\forall i\in [1,n), a_i \le a_{i+1}, b_i \le b_{i+1}$.
- .
There is a real-valued sequence of length such that . Find the maximum possible variance of .
You only need to output the result after multiplying the answer by . It is easy to prove that this is an integer.
Input Format
The first line contains one integer .
The second line contains integers .
The third line contains integers .
Output Format
One line containing one integer, which is the answer.
2
1 10
1 10
81
3
1 2 3
3 4 5
26
Hint
The variance of a sequence of length is $\dfrac{1}{n}\sum\limits_{i=1}^n (a_i-\overline{a})^2$, where .
During the computation for this problem, numbers exceeding the range of long long may appear. In that case, you may need to use __int128.
We provide the following code, which can be used to output a value of type __int128:
void print(__int128 x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x<10)
{
putchar(x+48);
return;
}
print(x/10);
putchar(x%10+48);
}
Constraints: for of the data, , .
: , .
: , .
: , .
: , .
: no special constraints.
Sample Explanation 1
can only be .
Sample Explanation 2
One optimal is .
Translated by ChatGPT 5