#P6863. [RC-03] 上下求索

[RC-03] 上下求索

Description

There is an nn-variable quadratic equation about xi(i{1,2,3,...,n},xiR)x_i(i∈\{1,2,3,...,n\},x_i∈\mathbb{R}):

$$\sum_{i=1}^na_ix_i^2+\sum_{i=1}^{n-1}b_ix_ix_{i+1}=m$$

In this equation, please find the range of values of x1x_1 that guarantees the equation has at least one solution.

It is guaranteed that x1x_1 has both a lower bound and an upper bound.

Input Format

The input has three lines.

The first line contains two integers n,mn,m.

The second line contains nn integers aia_i, where i{1,2,3,..,n}i∈\{1,2,3,..,n\}.

The third line contains n1n-1 integers bib_i, where i{1,2,3,..,n1}i∈\{1,2,3,..,n-1\}.

Output Format

Output one line with two integers separated by a space, representing the lower bound and upper bound of x1x_1 (it is guaranteed that the output is always integers).

5 16
2 2 2 2 1
2 2 2 2
-4 4

Hint

[Sample 11 Explanation]

The original equation is $2x_1^2+2x_1x_2+2x_2^2+2x_2x_3+2x_3^2+2x_3x_4+2x_4^2+2x_4x_5+x_5^2=16$.

When x1=4x_1=-4, we have x1=4x_1=-4; x2=4x_2=4; x3=4x_3=-4; x4=4x_4=4; x5=4x_5=-4.
When x1=4x_1=4, we have x1=4x_1=4; x2=4x_2=-4; x3=4x_3=4; x4=4x_4=-4; x5=4x_5=4.
When x1>4x_1>4 or x1<4x_1<-4, the left-hand side of the original equation must be >16>16.
Therefore, 4x14-4\leq x_1\leq 4.


[Constraints]

For 4%4\% of the testdata, n=1n=1.

For 16%16\% of the testdata, n2n\le 2.

For another 16%16\% of the testdata, n8n\le 8, m30m\le 30.

For 60%60\% of the testdata, n103n\le 10^3.

For 100%100\% of the testdata, 1ai,bi,m1091\le a_i,b_i,m\leq 10^9, 1n5×1051\le n\leq 5\times 10^5.

Translated by ChatGPT 5