#K78522. Find Three Numbers Summing to Target

    ID: 35105 Type: Default 1000ms 256MiB

Find Three Numbers Summing to Target

Find Three Numbers Summing to Target

You are given a target sum T and a list of integers. Your task is to find three distinct numbers from the list such that their sum equals the target, i.e. find A, B, C satisfying $$A+B+C=T$$. If multiple valid triplets exist, output the lexicographically smallest triplet (when the numbers are sorted in increasing order). If no triplet exists, output "No Solution".

Note: Although the list may contain duplicate elements, the three numbers chosen must be selected from distinct positions.

inputFormat

The input begins with an integer T indicating the number of test cases. Each test case consists of two lines:

  • The first line contains two integers: the target sum and an integer n representing the number of elements in the list.
  • The second line contains n space-separated integers.

outputFormat

For each test case, output a single line. If a valid triplet exists, print the three numbers in increasing order separated by a space; otherwise, print "No Solution".

## sample
2
10 9
1 2 3 4 5 6 7 8 9
15 5
2 2 2 2 2
1 2 7

No Solution

</p>