#C6371. Pair Sum Query in an Array

    ID: 50124 Type: Default 1000ms 256MiB

Pair Sum Query in an Array

Pair Sum Query in an Array

You are given an array of integers and a target integer. Your task is to determine whether there exist two distinct indices i and j (i ≠ j) such that:

ai+aj=targeta_i + a_j = \text{target}

If such a pair exists, output True; otherwise, output False. This is a typical two-sum problem often solved using hashing or two-pointer techniques.

Example:

  • For arr = [1, 2, 3, 4] and target = 5, one valid pair is (1,4), so the answer is True.

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  1. The first line contains two integers n and target, where n is the number of elements in the array.
  2. The second line contains n space-separated integers representing the elements of the array.

For example:

4 5
1 2 3 4

outputFormat

Output a single line to standard output (stdout) containing either True or False (without quotes), depending on whether a pair exists that sums up to the target value.

## sample
4 5
1 2 3 4
True