Driver code
int main ( ) { int a [ ] = { 1 , 1 , 2 , 2 , 2 , 3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; pair < int , int > queries [ ] = { { 0 , 4 } , { 1 , 2 } , { 2 , 5 } , { 2 , 3 } , { 2 , 4 } } ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ; int k = 3 ; cout << getFinalSum ( a , n , queries , q , k ) ; return 0 ; }