#K8091. Maximum Issue Difference

    ID: 35635 Type: Default 1000ms 256MiB

Maximum Issue Difference

Maximum Issue Difference

You are given a list of projects with reported issues and a set of queries. Each query specifies a range \( [L, R] \) (1-indexed) and asks you to determine the maximum difference between the highest and lowest number of issues reported among the projects in that range. The difference is computed as:

\( \text{difference} = \max\{B_L, B_{L+1}, \ldots, B_R\} - \min\{B_L, B_{L+1}, \ldots, B_R\} \)

Your task is to process all queries and output the corresponding difference for each.

inputFormat

The input is given in the following format:

  • The first line contains an integer \( n \), the number of projects.
  • The second line contains \( n \) space-separated integers representing the issues reported for each project.
  • The third line contains an integer \( q \), the number of queries.
  • Each of the next \( q \) lines contains two integers \( L \) and \( R \) (1-indexed) which denote a query.

outputFormat

For each query, output a single line containing the maximum difference between the issues reported in the specified range.

## sample
6
5 3 8 6 7 2
4
1 6
2 4
3 5
1 3
6

5 2 5

</p>