#K88627. Pair with Given Sum
Pair with Given Sum
Pair with Given Sum
You are given an integer array A
and a target integer K
. Your task is to determine whether there exist two distinct elements in the array whose sum equals K
. If such a pair exists, print True
; otherwise, print False
.
Note: The solution must read input from standard input (stdin) and write the result to standard output (stdout). The expected time complexity is O(n) on average using appropriate data structures.
The input will be provided in the following format:
- The first line contains two integers:
n
(the number of elements in the array) andK
(the target sum). - The second line contains
n
space-separated integers representing the elements ofA
.
The output is a single line containing either True
or False
.
inputFormat
The first line contains two integers n
and K
separated by a space, where:
n
denotes the number of elements in the array.K
is the target sum.
The second line contains n
space-separated integers representing the array elements.
outputFormat
Output a single line containing True
if there exists a pair of distinct indices i and j such that A[i] + A[j] = K
; otherwise, output False
.
6 16
1 4 45 6 10 8
True