#K76217. Maximum Load Query

    ID: 34594 Type: Default 1000ms 256MiB

Maximum Load Query

Maximum Load Query

Problem Statement:

You are given load values recorded for n servers over m time intervals. The data is provided as a matrix with m rows and n columns, where each row represents an interval and each column represents a server. You are also given q queries. Each query is described by two integers l and r, representing the inclusive range of servers (1-indexed). For each query, you must calculate the maximum load value observed among the servers in the range [l, r] across all intervals.

The mathematical formulation for each query is given by:

$$\max_{1 \leq i \leq m} \; \max_{l \leq j \leq r} \; load_{i,j} $$

Print the result for each query on a new line.

inputFormat

Input Format:

The first line contains two space-separated integers n and m, representing the number of servers and the number of intervals, respectively. The next m lines each contain n space-separated integers, representing the load values for each interval.

The following line contains a single integer q, the number of queries. Each of the next q lines contains two space-separated integers, l and r, indicating the query range (1-indexed).

outputFormat

Output Format:

For each query, output a single integer — the maximum load value among the servers in the range [l, r] across all intervals. Each result should be printed on its own line.## sample

5 3
1 4 3 2 5
2 1 6 3 1
4 5 2 9 7
2
1 3
3 5
6

9

</p>