TopCoder

Caido
Waimai

User's AC Ratio

93.3% (56/60)

Submission's AC Ratio

38.8% (150/387)

Tags

Description

given a sequence B=B0,B1,,BN1
for each query (P,K), find the minimum S
s.t. there are at least K entries in B that satisfies

  • |Pi|S
  • BiS

where Bi denotes the ith entry of B

Input Format

The first line contains two integers N,M.
The second line contains N integers separated with spaces. This is the sequence B.
The following M lines are M queries and each query is consists of two integers P,K.

Output Format

For each query, you should output one integer denoting your answer.

Sample Input 1

10 2
1 2 3 2 10 2 3 3 3 2
1 3
3 3

Sample Output 1

2
2

Hints

1N105
1M105
1BiN
0P<N
1KN

Problem Source

Subtasks

No. Testdata Range Score
1 0 10
2 1 10
3 2 10
4 3 10
5 4 10
6 5 10

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 2500 131072 262144 1
1 2500 131072 262144 2
2 2500 131072 262144 3
3 2500 131072 262144 4
4 2500 131072 262144 5
5 2500 131072 262144 6