407511: GYM102821 C Cycle Function

Memory Limit:256 MB Time Limit:5 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Cycle Functiontime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Fish is learning functions! He has a linear function $$$f(x) = Ax + B$$$ and $$$N$$$ numbers $$$x_1,x_2,\cdots,x_N$$$. Now he is curious about for each function $$$g(x)$$$ in

$$$\left\{ \begin{matrix} g_1(x)=c_1x+d_1\\ g_2(x)=c_2x+d_2\\ \vdots\\ g_M(x)=c_Mx+d_M \end{matrix} \right\}$$$

how to calculate the difference between $$$f(g(x))$$$ and $$$g(f(x))$$$.

As smart as Fish is, he soon comes up with a function $$$D(x)=|f(g(x))-x|+|g(f(x))-x|$$$ and uses the sum over $$${x_1,x_2,\cdots,x_N}$$$ as the difference.

Can you tell him all the differences immediately?

Input

The first line of input contains an integer $$$T$$$, representing the number of test cases.

Then for each test case:

The first line contains two integers $$$N$$$, $$$M$$$ as mentioned above and then two real numbers $$$A$$$, $$$B$$$ indicating the given function $$$f(x) = Ax + B$$$.

The second line contains $$$N$$$ real numbers $$$x_1,x_2,\cdots,x_N$$$.

Then $$$M$$$ lines follow, each line containing two real numbers $$$c_i$$$, $$$d_i$$$ indicating a function $$$g_i(x)=c_ix+d_i$$$ mentioned above.

All numbers in the same line are separated by one space.

Output

For each test case, you should output Case $$$x$$$: in the first line, where x indicates the case number starting from 1.

Then $$$M$$$ lines follow, the $$$i$$$-th line of which contains a real number representing the difference for given function $$$g_i(x)$$$.

Your answers will be considered correct if its absolute error does not exceed $$$10^{-6}$$$.

ExampleInput
2
3 2 2.0 3.0
1.0 2.0 3.0
0.4 -2.0
0.6 -5.0
3 2 2.5 2.0
1.0 2.0 3.0
0.4 -2.0
0.6 -5.0
Output
Case 1:
7.800000
28.200000
Case 2:
12.600000
36.900000
Note

$$$1\le T\le 100$$$

$$$1\le N, M\le 10^5$$$

$$$-100 \le A,B,x_i,c_i,d_i \le 100$$$

For $$$90\%$$$ test cases: $$$\max(N, M) \le 1000$$$

加入题单

上一题 下一题 算法标签: