#C3923. Counting Distinct Pairs That Sum to a Target
Counting Distinct Pairs That Sum to a Target
Counting Distinct Pairs That Sum to a Target
You are given an integer n representing the number of elements in a sequence, an integer t representing a target sum, and a sequence of n integers. Your task is to count the number of distinct pairs of elements in the sequence that add up to the target t.
A pair is considered distinct if the two numbers forming the pair (after sorting in non-decreasing order) have not appeared before. In other words, the pair \( (a, b) \) is the same as \( (b, a) \), and each unique combination should be counted only once.
Note: There is no requirement for the indices. Only the values matter.
For example, given the sequence [1, 2, 3, 7, 5, 8] and target 10, the distinct pairs that sum to 10 are \( (3,7) \) and \( (2,8) \), so the answer is 2.
inputFormat
The first line of input contains two integers n and t separated by a space, where n is the number of elements in the sequence and t is the target sum.
The second line contains n space-separated integers representing the sequence.
Constraints: It is guaranteed that the input values will be such that the computation can be done efficiently.
outputFormat
Output a single integer which is the number of distinct pairs of elements from the sequence that add up to the target sum t.
The output should be written to standard output (stdout).
## sample6 10
1 2 3 7 5 8
2