Riemann Sum Offset (Small)
InterviewTime limit1sMemory limit512 MB
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.
While working through integrals at boot camp, Mingyu wondered whether a well chosen 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 for him.
Input
The first line contains a positive integer , the degree of the polynomial. In this problem .
The second line contains the coefficients in decreasing order of degree. (, )
The third line contains the integers and , the start and the end of the integration interval, and , the number of pieces the interval is split into. (, )
Output
Print on one line the that makes the approximation equal the true integral. Round it to four decimal places and always print all four, so an answer of is printed as 0.2500.
If no such exists, print -1.
Hint
The integral of a power is computed like this.