#C4418. Pair with Sum

    ID: 47954 Type: Default 1000ms 256MiB

Pair with Sum

Pair with Sum

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

If such a pair exists, output 1. Otherwise, output 0.

Note: The pair of elements must be distinct. The list may be empty or contain only one element.

The solution should work efficiently even if the list contains a large number of elements. Using a hashing-based approach is recommended to achieve an optimal solution.

Mathematically, you need to check if there exist indices i and j with i ≠ j such that:

ai+aj=ka_i + a_j = k

inputFormat

The input consists of two lines:

  • The first line contains two integers n and k where n is the number of elements in the array and k is the target sum.
  • The second line contains n space-separated integers representing the array elements. If n is 0, the second line will be empty.

outputFormat

Output a single integer: 1 if there exists a pair of distinct elements in the array whose sum is equal to k, otherwise 0.

## sample
4 17
10 15 3 7
1