#K45667. Pair Sum Indices
Pair Sum Indices
Pair Sum Indices
You are given an integer N, an integer X, and an array of N integers. Your task is to identify two distinct indices i and j such that the sum of the values at these indices equals X. The output should present the two indices in non-decreasing order.
If no pair exists, output -1 -1
.
The problem can be mathematically formulated as: $$ \text{Find indices } i, j \text{ such that } arr[i] + arr[j] = X. $$
inputFormat
The first line contains two integers N and X separated by a space.
The second line contains N integers representing the array values, separated by spaces.
outputFormat
Output two space-separated integers representing the indices of the two numbers whose sum is X in non-decreasing order. If no such pair exists, output -1 -1
.
4 7
1 2 3 4
2 3