#C13260. Find Pair with Sum
Find Pair with Sum
Find Pair with Sum
Given an array of integers and a target value \(T\), your task is to find two distinct indices \(i\) and \(j\) such that \(a_i + a_j = T\). The indices are 0-based, and if multiple pairs exist, output the first valid pair found by scanning from left to right. If no such pair exists, output None
.
For example, if the input array is [2, 7, 11, 15] and \(T=9\), then the answer is 0 1
because \(2+7=9\). Please note that the input will be taken from standard input and the output should be printed to standard output.
inputFormat
The input consists of three lines:
- The first line contains an integer \(n\), representing the number of elements in the array.
- The second line contains \(n\) space-separated integers, the elements of the array.
- The third line contains an integer representing the target sum \(T\).
outputFormat
If there exists a pair of indices \(i\) and \(j\) such that \(a_i + a_j = T\), print the two indices separated by a single space. If no such pair exists, print None
.
4
2 7 11 15
9
0 1