#C8227. Find Pair with Given Sum
Find Pair with Given Sum
Find Pair with Given Sum
You are given a series of test cases. In each test case, you are provided with a list of integers and a target sum \(S\). Your task is to find a pair of integers \((a, b)\) from the list such that:
[ a + b = S ]
If multiple pairs exist, output the first valid pair discovered when scanning the list from left to right. If no such pair exists, output NO PAIR
.
Note: The output pair should be printed in the order in which they are found (i.e. if the number \(x\) is encountered and its complement \(S-x\) has been seen before, output \((S-x, x)\)).
inputFormat
The first line contains an integer \(T\) representing the number of test cases. Each test case is described by two lines:
- The first line contains two space-separated integers \(N\) and \(S\), where \(N\) is the number of integers and \(S\) is the target sum.
- The second line contains \(N\) space-separated integers.
Read input from stdin
.
outputFormat
For each test case, print a single line:
- If a valid pair is found, output the two integers separated by a space.
- If no such pair exists, output
NO PAIR
.
Write output to stdout
.
6
4 10
1 2 3 7
5 8
1 2 4 5 6
3 10
1 2 3
1 0
0
5 1000000
500000 500000 1 2 3
4 -1
-2 -1 0 1
3 7
2 6
NO PAIR
NO PAIR
500000 500000
-1 0
</p>