#C9081. Find a Pair with Given Sum
Find a Pair with Given Sum
Find a Pair with Given Sum
Problem Statement:
You are given an array \(a\) of \(n\) integers and an integer \(target\). Your task is to find two distinct indices \(i\) and \(j\) (with \(1 \leq i < j \leq n\)) such that:
\[ a_i + a_j = target \]If such a pair exists, output the two indices (1-indexed). If multiple pairs exist, any one of them is acceptable. Otherwise, output -1.
Note: The indices in the output must be printed as two space-separated integers.
inputFormat
The input is given via standard input (stdin) and 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 (a).
- The third line contains an integer (target), the sum you need to find.
outputFormat
Print two space-separated integers representing the 1-indexed positions (i) and (j) such that (i < j) and (a_i + a_j = target). If no such pair exists, print -1.## sample
5
1 2 3 4 5
5
2 3