#C14371. Pair Sum Problem

    ID: 44013 Type: Default 1000ms 256MiB

Pair Sum Problem

Pair Sum Problem

Given an array of integers and a target sum \(T\), determine whether there exist two distinct elements in the array whose sum equals \(T\). In other words, given an array \(A\) of size \(n\) and an integer \(T\), check if there exist indices \(i\) and \(j\) (with \(i \neq j\)) such that \(A_i + A_j = T\).

An efficient solution should ideally run in \(O(n)\) time by using a hash set to keep track of the required complement values.

Example: For the array [2, 4, 7, 1] and target \(T = 5\), the output is True because 4 and 1 add up to 5.

inputFormat

The input consists of two lines:

  • The first line contains two integers \(n\) and \(T\), where \(n\) is the number of elements in the list and \(T\) is the target sum.
  • The second line contains \(n\) space-separated integers representing the array elements.

outputFormat

Output True if there exists a pair of distinct elements in the array whose sum equals \(T\), otherwise output False. The result should be printed to STDOUT.

## sample
4 5
2 4 7 1
True