## Wesley's Anger Contest 5 Problem 2 - MATH 137 at Squirreloo

View as PDF

Points: 7 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

At the University of Squirreloo, first-year squirrels in the math faculty have to take MATH 137: calculus, everyone's favourite branch of math! In this course they learn about convergent sequences, where values in a sequence get arbitrarily close to a limit. However, said sequences are infinite, and infinity is a concept too difficult to tackle immediately for our young squirrels, so they'll first discuss sequences of finite length - namely, an array of length . We'll say an array converges to a limit with an accuracy of if there exists a suffix of such that all elements in differ from by at most . Given an array of length , the squirrels are given assignment questions of the form , and are tasked to determine whether or not converges to with an accuracy of , and if so, to find the length of the longest suffix of that fulfills the definition above.

#### Constraints

For this problem, you will be required to pass all the samples in order to receive any points. In addition, you must pass all previous subtasks to earn points for a specific subtask.

for all

#### Input Specification

On the first line will be two integers and , the length of the array and the number of assignment questions respectively.

The second line will contain integers , the array .

The following lines will each contain two integers and , the limit and accuracy to test for on the assignment question.

#### Output Specification

This problem is graded with an identical checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n character and that there are no trailing spaces.

Output lines. The line should contain the length of the longest suffix of such that all elements in the suffix differ from by at most . If such a suffix does not exist, output .

#### Sample Input 1

8 5
1 5 4 6 -2 3 4 0
0 4
2 2
1 5
-1 0
5 5

#### Sample Output 1

4
3
8
0
3

#### Sample Input 2

5 5
1 2 3 4 5
5 1
4 1
2 2
2 3
1 5

#### Sample Output 2

2
3
0
5
5