#K57612. Two Sum Problem

    ID: 30460 Type: Default 1000ms 256MiB

Two Sum Problem

Two Sum Problem

Problem Description

You are given an array of integers and a target integer. Your task is to find two distinct indices i and j such that:

\( nums[i] + nums[j] = target \)

If such a pair exists, print the indices separated by a space. If there is no such pair, output -1.

The input will be provided via standard input (stdin) and your output should be written to standard output (stdout).

inputFormat

The input consists of three parts provided via stdin:

  1. An integer n representing the number of elements in the array.
  2. n space-separated integers representing the elements of the array.
  3. An integer target representing the desired sum.

Example:

5 1 2 3 4 5 9

outputFormat

Output a single line to stdout containing two space-separated indices if a pair is found that adds up to target. If no such pair exists, output -1.## sample

4
2 11 7 15
9
0 2