Input: arr[][]={ {1, 2}, {3, 2}, {4, 5}, {7, 1}, {10, 4} }, queries[] = { {0, 12}, {4, 6}, {2, 8} }
Output: 14, 5, 8
Explanation:
queries[0]: we'll take score all elements i.e. 2 + 2 + 5 + 1 + 4 = 14
queries[1]: Only the 3rd element can be considered so the score will be 5.
queries[2]: we'll take elements from 2nd, 3rd and 4th position i.e. 2 + 5 + 1 = 8
Input: arr[][]={ {1, 6}, {12, 5}, {3, 4, }, {14, 3}, {5, 2} }, queries[] = { {10, 12}, {1, 5}, {10, 15} }
Output: 5, 12, 8
Explanation:
queries[0] : only 2nd element will be considered so the score will be 5
queries[1]: we'll take score of elements from 1st, 3rd and 5th position i.e. 6 + 4 + 2 = 12
queries[2]: we'll take score of elements from 2nd and 4th position i.e. 5 + 3 = 8
Below is the implementation of the above approach.