#K72772. Can Sum To Target
Can Sum To Target
Can Sum To Target
Given an array of integers and an integer target, determine if there exist two distinct elements in the array whose sum is exactly equal to the target. In other words, for a given array \(A = [a_1,a_2,\dots,a_n]\) and an integer \(T\), decide whether there exist indices \(i\) and \(j\) (with \(i \neq j\)) such that \(a_i + a_j = T\). The solution must read input from stdin
and output the result to stdout
.
inputFormat
The input is given via standard input (stdin
). The format is as follows:
- The first line contains an integer \(n\), the number of elements in the array.
- If \(n > 0\), the second line contains \(n\) space-separated integers representing the elements of the array. If \(n = 0\), this line is omitted.
- The last line contains an integer \(T\), the target sum.
outputFormat
The output should be sent to standard output (stdout
) and consist of a single line. Print true
if there exists a pair of distinct elements in the array whose sum is exactly equal to \(T\); otherwise, print false
.
4
2 7 11 15
9
true
</p>