Indexed Numbers

0

0 votes
Hard
Problem

Construct an array of n given elements. Then print the elements from the index i to the index j, such that the sum of the elements from i (inclusive) to j (inclusive) is exactly ‘a’ (given as input). Print -1 if no such sequence is possible. In case of multiple answers the smallest i (primary criterion) and smallest j (secondary criterion) should be considered. 

Constraints:
1 <= t <= 20 //no of test cases
1 <= n <= 100
 

Input and Output format: First line of the input is t no of test cases. For each test case a number n is the input followed by the n numbers. Followed by and integer a. All the numbers are well with in the range of integer.

Input:
2
6
2 3 6 5 4 7
9
5
3 6 5 4 7
15

Output:
1 6 // 2 + 7 = 9 and 5 +4 = 9 too but i = 1, j = 6 are the smallest
-1 // no such sequence

Note: The numbers taken are 1-indexed.

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?