The Chocolate Shop

3

2 votes
Easy
Problem

Roshan and Bandal are two best friends. One day, they go to The Chocolate Shop. There are "n" different flavours of candies in the shop. The cost of the candies are represented by array C such as C1, C2, C3, ....., Cn. Roshan and Bandal have collectively "m" amount of money together. Also, they want to buy two distinct favours of candies and use their entire money. Help them to buy the candies by returning indices of candies (consider 1 based indexing) they should buy.

Assume there is always a unique solution present.

 

Input 

The first line contains an integer, t, the number of trips to The Chocolate Shop.

Each of the next sets of lines are as follows:

  • The first line contains an integer, m, amount of money they have together.
  • The second line contains an integer, n, the size of the array C.
  • The third line contains n space-separated integers denoting the cost of each flavour.

Output

  • Print two space-separated integers denoting the respective indices for the two distinct flavors they choose to purchase in ascending order.

Constraints

  • 1 <= t <= 50
  • 2 <= m <= 109
  • 2 <= n <= 5 * 104
  • 1 <= C[i] <= 109, where 1 <= i <= N (1 based indexing)
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Roshan and Bandal  make the following two trips to the shop:

  1. The first time, they pool together m = 4 dollars. There are five flavors available that day and flavors 1 and 4 and have a total cost of  1 + 3 = 4.
  2. The second time, they pool together m = 4 dollars. There are four flavors available that day and flavors 1 and 2 and have a total cost of 2 + 2 = 4 .
Editor Image

?