Two Sum (Indices)
Riverbend Gift Company sells vouchers that have to be spent on exactly two items, and the two prices together must match the voucher's face value — no change given, no topping up. The till already holds today's price list in shelf order. The picker who fetches the goods works from shelf positions, not from prices, so positions are what the screen has to show.
Task: Print the positions of the two prices that together match the voucher value.
Input
Two lines. The first holds a single integer, the voucher value. The second holds between 2 and 1000 integers separated by single spaces — the price list, in shelf order. Exactly one pair of positions matches the voucher value.
Output
One line holding the two positions separated by a single space. Count positions from 0, so the first price sits at position 0. Print the smaller position first.
Example:
Input:
9
2 7 11 15
Output:
0 1
(2 + 7 = 9, at indices 0 and 1)
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in