#C1824. Two Sum Problem

    ID: 45072 Type: Default 1000ms 256MiB

Two Sum Problem

Two Sum Problem

You are given a list of integers \(nums\) and an integer \(target\). Your task is to find two distinct indices \(i\) and \(j\) in the list such that \(nums[i] + nums[j] = target\). If such a pair exists, output the indices (0-indexed) as two space-separated integers; otherwise, output -1.

It is guaranteed that each input has at most one solution. You should design an algorithm with an expected time complexity better than \(O(n^2)\) for typical inputs.

Note: The input will be read from standard input (stdin) and output should be written to standard output (stdout).

inputFormat

The first line of input contains two integers: \(n\) (the number of elements in the list) and \(target\). The second line contains \(n\) space-separated integers representing the list \(nums\).

outputFormat

If there exists a pair of indices \(i\) and \(j\) such that \(nums[i] + nums[j] = target\), print the two indices separated by a space. Otherwise, print -1.

## sample
4 9
2 7 11 15
0 1