Artsem is on vacation and wants to buy souvenirs for his two teammates. There are \(n\) souvenir shops along the street. In \(i^{th}\) shop Artsem can buy one souvenir for \(a_i\) dollars, and he cannot buy more than one souvenir in one shop. He doesn't want to introduce envy in his team, so he wants to buy two souvenirs with least possible difference in price.
Artsem has visited the shopping street \(m\) times. For some strange reason on the \(i^{th}\) day only shops with numbers from \(l_i\) to \(r_i\) were operating (weird? yes it is, but have you ever tried to come up with a reasonable legend for a range query problem?). For each visit, Artsem wants to know the minimum possible difference in prices of two different souvenirs he can buy in the opened shops.
In other words, for each Artsem's visit you should find the minimum possible value of \(|a_s-a_t|\) where \(l_i \leq s, t \leq r_i, s \ne t\).
Subtasks # | Score | Constraits |
---|---|---|
1 | 21 | \(a_i\) is in non-decreasing order |
2 | 30 | \(n \leq 1000\) \(m \leq 1000\) |
3 | 49 | - |
The first line contains \(n\).
The next line contains \(n\) integers, where the \(i^{th}\) integer represents \(a_i\)
The next line contains \(m\)
The next \(m\) lines contains 2 integers, where the \(i^{th}\) of these lines represents \(l_{i}\) and \(r_i\)
Print the answer to each query in a separate line.
Sample Input 1 | Sample Output 1 |
8
|
0
|
Subtask | Score |
---|---|
1 | 21 |
2 | 30 |
3 | 49 |
4 | 0 |