P15640 [CodeChef] MAXEXPR
提高-
题目描述

Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef had three sequences of real numbers $k_{1}, k_{2}, \ldots, k_{N}$, $c_{1}, c_{2}, \ldots, c_{N}$ and $x_{1}, x_{2}, \ldots, x_{N}$. Unfortunately, he lost the sequence $x$; the only thing he remembers about it is that
$$x_{1} \cdot k_{1} + x_{2} \cdot k_{2} + \ldots + x_{N} \cdot k_{N} = 0 \,.$$

Chef's favourite expression is
$$\sqrt{x_{1}+c_{1}} + \sqrt{x_{2}+c_{2}} + \ldots + \sqrt{x_{N}+c_{N}} \,.$$
Its value is defined only if $x_{i}+c_{i} ≥ 0$ for each valid $i$. Let's denote the maximum value of this expression$ $ (over all sequences $x$ such that it is defined) by $F$.

Help Chef find $F$ and a sequence $x_{1}, x_{2}, \ldots, x_{N}$ such that the value of Chef's expression is $F$, or determine that there is no solution (the value of Chef's expression is always undefined).

------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ real numbers $k_{1}, k_{2}, \ldots, k_{N}$.
The third line contains $N$ real numbers $c_{1}, c_{2}, \ldots, c_{N}$.

All real numbers are given with exactly two digits after the decimal point.

------ Output ------
For each test case, if there is no solution, print a single line containing one integer $-1$. Otherwise, print a single line containing $N+1$ space-separated real numbers $F, x_{1}, x_{2}, \ldots, x_{N}$.

It can be proved that if a solution exists, then it is unique. Your answer will be considered correct if the absolute or relative error of each number on the output does not exceed $10^{−2}$.

------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$2 ≤ N ≤ 10^{5}$
$0 < k_{i} ≤ 2,000$ for each valid $i$
$|c_{i}| ≤ 2,000$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$

------ Subtasks ------
Subtask #1 (15 points): $N = 2$

Subtask #2 (15 points): $k_{i} = 1$ and $c_{i} = 0$ for each valid $i$

Subtask #3 (15 points): $k_{i} = 1$ for each valid $i$

Subtask #4 (15 points): $c_{i} = 0$ for each valid $i$

Subtask #5 (40 points): original constraints

----- Sample Input 1 ------
5
4
1.00 2.00 3.00 4.00
5.00 6.00 7.00 8.00
3
1.23 8.90 5.67
-2.34 -9.01 -6.78
3
1.00 1.00 1.00
1.23 8.90 -5.67
2
1.23 8.90
-5.67 2.34
2
1.23 8.90
5.67 -2.34
----- Sample Output 1 ------
12.0761472885 28.6000000000 2.4000000000 -3.2666666667 -5.9000000000
-1
3.6578682316 0.2566666667 -7.4133333333 7.1566666667
3.5802375027 15.5642936942 -2.1510203645
-1
----- explanation 1 ------
Example case 1: The optimal solution is $x = (28.6, 2.4, -49/15, -5.9)$. Then, $x_{1} \cdot k_{1} + x_{2} \cdot k_{2} + x_{3} \cdot k_{3} + x_{4} \cdot k_{4} = 28.6 \cdot 1 + 2.4 \cdot 2 - 49 \cdot 3 / 15 + (-5.9) \cdot 4 = 0$, and $F = \sqrt{28.6+5}+\sqrt{2.4+6}+\sqrt{-49/15+7}+\sqrt{-5.9+8} \doteq 12.076$. This is the maximum value of Chef's expression.

Example case 2: For each $i$, $c_{i}$ is negative, but $x_{i}+c_{i}$ must be non-negative, so $x_{i}$ must be positive. However, all $k_{i}$ are also positive, so $x_{1} k_{1} + x_{2} k_{2} + \ldots + x_{N} k_{N}$ cannot be $0$. There is no solution.

输入格式

见题面

输出格式

见题面

样例输入
5 4 1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 3 1.23 8.90 5.67 -2.34 -9.01 -6.78 3 1.00 1.00 1.00 1.23 8.90 -5.67 2 1.23 8.90 -5.67 2.34 2 1.23 8.90 5.67 -2.34
样例输出
12.0761472885 28.6000000000 2.4000000000 -3.2666666667 -5.9000000000 -1 3.6578682316 0.2566666667 -7.4133333333 7.1566666667 3.5802375027 15.5642936942 -2.1510203645 -1