#C10833. Count Unique Pairs with Target Sum

    ID: 40082 Type: Default 1000ms 256MiB

Count Unique Pairs with Target Sum

Count Unique Pairs with Target Sum

You are given an integer array arr and an integer target. Your task is to find the number of unique pairs of elements (a, b) in the array such that their sum is equal to target. Each element in the array can be used at most once across all pairs, and a pair is considered unique based on its values (i.e. (a, b) is the same as (b, a)).

Note: Even if there are multiple ways to form a pair with the same values, it should only be counted once.

For example, given the array [2, 2, 2, 2] and target = 4, you can only form one unique pair (2, 2).

Input/Output requirement: Your program should read the input from stdin and print the output to stdout.

inputFormat

The first line contains two space-separated integers: n (the size of the array) and target (the target sum).

The second line contains n space-separated integers, representing the elements of the array.

Example:

6 5
1 3 2 2 3 4

outputFormat

Print a single integer: the number of unique pairs whose sum is equal to target.

Example:

2
## sample
6 5
1 3 2 2 3 4
2