#C4766. Two Sum Indices

    ID: 48340 Type: Default 1000ms 256MiB

Two Sum Indices

Two Sum Indices

You are given an array of integers and a target integer. Your task is to find two distinct indices such that the numbers at those indices add up exactly to the target. It is guaranteed that there is exactly one solution, and you may not use the same element twice.

The expected solution should ideally run in linear time using a hash table (or similar) to achieve an optimal solution. Note that indices are zero-based.

Mathematical Formulation:

Given an array \(A = [a_0, a_1, \dots, a_{n-1}]\) and an integer \(T\), find indices \(i\) and \(j\) such that \[ a_i + a_j = T \] and \(i \neq j\).

inputFormat

The input is read from stdin and consists of three lines:

  • The first line contains an integer \(n\) denoting the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the array.
  • The third line contains an integer representing the target sum \(T\).

outputFormat

Output to stdout the two indices (separated by a single space) of the numbers that add up to the target.

## sample
4
2 7 11 15
9
0 1