Given an array 'A' of size 'N' containing integers. You need to answer 'Q' queries of type [ L R X Y ]. In each of the query you need to select at least 'X' elements and at most 'Y' elements from range 'L' to 'R' of the array 'A' such that their sum is maximum.
Output the maximum sum achievable for each of the query.
Example :
N = 5 A = [ 1, 2, -1, -2, 3 ] Q = [ [ 1, 3, 1, 2 ] , [ 3, 4, 1, 2 ] ]
Output :
3, -1
Expanation :
For query 1, we select integers 1 and 2 to get the sum 3. This is the maximum sum achievable in the range index 1 to 3.
For query 2, we need to select at least 1 element so we select -1 to get maximum sum -1.
Note :
The selected elements in the range L to R need not be consecutive. You can > select subsequence of integers to maximise the sum.
Constraints :
1<=N<=10^5 1<=Q<=10^5 -10^8 <= A[i] <= 10^8 1<=L<=R<=N 1<=X<=Y<=R-L+1
I tried to think of some approaches but could not find any algo for the above constraints. Any help/hint would be appreciated.