#C13942. Two Sum Problem
Two Sum Problem
Two Sum Problem
You are given an array of integers and a target integer. Your task is to find two distinct indices such that the sum of the numbers at those indices equals the target value. If there is no such pair, output -1.
The input is provided via standard input (stdin) and the answer must be printed to standard output (stdout). The first line contains an integer n which is the number of elements in the array. The second line contains n space-separated integers. The third line contains the target integer.
If there exists at least one pair whose sum equals the target, print the two indices (0-indexed) separated by a space. If there are multiple correct answers, you may print any of them. If no such pair exists, print -1.
Note: Use the format below for any formulas. For example, the sum condition is given by: \(a_i + a_j = target\), where \(0 \leq i, j < n\) and \(i \ne j\).
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 third line contains a single integer representing the target sum.
outputFormat
If a pair (i, j) exists such that \(a_i + a_j = target\), output the two indices (0-indexed) separated by a space. Otherwise, output -1.
## sample4
2 7 11 15
9
0 1