#C10218. Unique Pairs Sum Finder
Unique Pairs Sum Finder
Unique Pairs Sum Finder
You are given several test cases. For each test case, you are provided an integer N (the number of elements), a list of N integers, and a target integer t. Your task is to identify all unique pairs of indices (i, j), where 0 ≤ i < j ≤ N-1, such that the sum of the corresponding elements equals t. A pair (i, j) is considered the same as (j, i) and should only be counted once.
Input constraints are as follows:
- The number of test cases, T, must satisfy \(1 \leq T \leq 10\). If this constraint is violated, output Invalid Test.
- For each test case, the number of elements, N, must satisfy \(1 \leq N \leq 100\). If this constraint is violated for any test case, output Invalid Input immediately.
Read the input from standard input (stdin) and write the result to standard output (stdout). Each test case should produce an output line, which is a list of unique pairs in the format [(i, j), ...]
. If no valid pairs exist for a test case, output an empty list []
.
inputFormat
The input is given in the following format from standard input:
T N a1 a2 ... aN t ... (repeat the above three lines for each test case)
Where:
- T is the number of test cases.
- N is the number of elements in the list for the current test case.
- a1, a2, ..., aN are the list of integers.
- t is the target integer.
outputFormat
For each test case, output a single line containing a list of unique pairs. Each pair should be displayed in the format (i, j)
and the entire output should be enclosed in square brackets. For example: [(0, 3), (1, 2)]
.
If no pairs sum up to the target, output an empty list: []
.
If the input constraints are violated, output Invalid Test (if T is invalid) or Invalid Input (if any N is invalid) and do not process further.
## sample5
4
1 2 3 4
5
3
1 2 3
7
5
1 2 3 4 5
100
6
1 2 3 4 5 6
7
4
-1 -2 -3 -4
-5
[(0, 3), (1, 2)]
[]
[]
[(0, 5), (1, 4), (2, 3)]
[(0, 3), (1, 2)]
</p>