#C13691. Find Unique Pairs with Given Sum

    ID: 43257 Type: Default 1000ms 256MiB

Find Unique Pairs with Given Sum

Find Unique Pairs with Given Sum

You are given an array of integers and a target integer. Your task is to find all unique pairs in the array whose sum is equal to the given target. Each pair should be represented as ( (a, b) ) with the smaller number first (i.e., (a \le b)). The final list of pairs must be sorted in ascending order first by (a) and then by (b).

Mathematically, you need to find all pairs ( (a, b) ) such that ( a + b = T ) and (a \le b), where (T) is the target sum.

inputFormat

The input is read from standard input and consists of two lines. The first line contains two space-separated integers: (n), the number of elements in the array, and (T), the target sum. The second line contains (n) space-separated integers representing the array. If (n = 0), the second line will be empty.

outputFormat

Print the resulting list of unique pairs in the exact format of a Python list of tuples. Each tuple must be displayed in the format ( (a, b) ) with a comma and a space between the values. The entire list should be enclosed in square brackets. If no valid pair exists, print an empty list: []## sample

7 7
2 4 3 5 7 8 -1
[(-1, 8), (2, 5), (3, 4)]