Under construction

Still being built. Things may change

Riemann Sum Offset (Small)

Interview

Time limit1sMemory limit512 MB

Summary
For a linear polynomial, find the offset epsilon in [0, dx] that makes the Riemann sum equal the exact integral, or print -1.
Level

Easy3 of 10

Topics
Math, Implementation, Binary search, Prefix sum
Solved
No attempts yet

Problem

The integral of a function can be approximated like this.

∫abf(x) dx≈∑k=0N−1f(a+k Δx+ϵ) Δx\int_a^b f(x)\,dx \approx \sum_{k=0}^{N-1} f(a + k\,\Delta x + \epsilon)\,\Delta x

Δx=b−aN,0≤ϵ≤Δx\Delta x = \frac{b-a}{N}, \qquad 0 \le \epsilon \le \Delta x

While working through integrals at boot camp, Mingyu wondered whether a well chosen ϵ\epsilon could make this approximation match the true integral exactly. Checking that by hand runs into decimal arithmetic he cannot do on paper. Write the program that finds such an ϵ\epsilon for him.

Input

The first line contains a positive integer KK, the degree of the polynomial. In this problem K=1K = 1.

The second line contains the coefficients c1,c2,…,cK+1c_1, c_2, \dots, c_{K+1} in decreasing order of degree. (0≤ci≤100 \le c_i \le 10, 1≤c1≤101 \le c_1 \le 10)

The third line contains the integers aa and bb, the start and the end of the integration interval, and NN, the number of pieces the interval is split into. (0≤a<b≤100 \le a < b \le 10, 1≤N≤101 \le N \le 10)

Output

Print on one line the ϵ\epsilon that makes the approximation equal the true integral. Round it to four decimal places and always print all four, so an answer of 0.250.25 is printed as 0.2500.

If no such ϵ\epsilon exists, print -1.

Hint

The integral of a power is computed like this.

∫abxm dx=bm+1−am+1m+1\int_a^b x^m\,dx = \frac{b^{m+1} - a^{m+1}}{m+1}

Examples2

  1. Example 1

    Input
    1
    1 0
    0 1 2
    
    Expected output
    0.2500
    
  2. Example 2

    Input
    1
    10 10
    0 10 1
    
    Expected output
    5.0000