Bob's teachers have conspired to give Bob a major assessment in each of their classes on the same day! Bob has l r
, output the greatest suffering of any subarray contained in the subarray from
Constraints
Subtask 1 [4%]
Subtask 2 [15%]
Subtask 3 [17%]
There are at most
Subtask 4 [24%]
There are at most
Subtask 5 [40%]
No additional constraints
Input Specification
The first line will contain two space-separated integers,
The next line will contain
The next l r
.
Output Specification
For each of the
Sample Input 1
6 4
3 5 2 3 5 1
2 2
1 3
1 4
2 6
Sample Output 1
25
25
26
30
Explanation for Sample 1
For the first query, the subarray
For the second query, the subarray
For the third query, the subarray
For the fourth query, the subarray
Sample Input 2
5 10
1 2 2 3 5
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
Sample Output 2
4
8
14
25
8
14
25
10
25
25
Sample Input 3
10 12
8 2 5 4 1 5 9 8 7 3
1 10
2 4
3 7
7 9
4 6
2 3
7 7
5 10
3 3
1 4
6 8
2 8
Sample Output 3
168
36
81
168
25
25
81
168
25
64
136
136
Comments