#C10272. Pair With Target Sum

    ID: 39459 Type: Default 1000ms 256MiB

Pair With Target Sum

Pair With Target Sum

You are given a list of integers and a target integer. Your task is to determine whether there exists a pair of distinct elements in the list whose sum equals the target value.

In mathematical terms, given an integer \( target \) and an array \( A = [a_1, a_2, \dots, a_n] \), you need to check if there exist indices \( i \) and \( j \) with \( i \neq j \) such that:

[ a_i + a_j = target ]

If such a pair exists, output True; otherwise, output False. The solution should work correctly for an empty list, a single element, negative numbers, zeros, and large values.

inputFormat

The input is given via stdin in the following format:

  • The first line contains two integers: ( n ), the number of elements in the array, and ( target ), the target sum.
  • The second line contains ( n ) integers separated by spaces.

Note: If ( n = 0 ), the second line will be empty.

outputFormat

Output a single line to stdout containing either True if there exists a pair of integers in the array whose sum is equal to ( target ), or False otherwise.## sample

4 17
10 15 3 7
True