#C2060. Two Sum
Two Sum
Two Sum
Given an array of integers and a target integer, your task is to find two distinct elements in the array such that their sum equals the target value. If such a pair exists, output the zero-indexed positions of the two numbers; otherwise, output -1.
The problem can be formulated mathematically as follows: $$a_i + a_j = target$$ where $$0 \leq i, j < n$$ and $$i \neq j$$.
You should read the input from stdin and write the answer to stdout.
inputFormat
The input consists of three lines:
- 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 a single integer representing the target sum.
outputFormat
If a valid pair is found, output two space-separated integers indicating the indices of the two numbers. If no such pair exists, output -1.## sample
4
2 7 11 15
9
0 1