#C2973. Two Sum Problem
Two Sum Problem
Two Sum Problem
Given an array of integers and a target integer (T), find two distinct numbers in the array whose sum equals (T). If such a pair exists, output their 0-indexed positions separated by a space; otherwise, output -1. There is at most one valid pair in the input.
For example, if the array is ([2, 7, 11, 15]) and (T = 9), the correct answer is:
0 1
inputFormat
The input is given via standard input in the following format:
- The first line contains an integer (n), the number of elements in the array.
- The second line contains (n) space-separated integers representing the array elements.
- The third line contains an integer (T), the target sum.
outputFormat
Output a single line. If a valid pair is found, print the two indices (0-indexed) separated by a space. Otherwise, print -1.## sample
4
2 7 11 15
9
0 1