← March 2025 questions

MARCH 2025 / ADVANCED / QUESTION 6

Question 6

Archived question

Try the question in your own editor, then check your output below.

THE QUESTION

Text from the official booklet. Refer to the PDF for original mathematical notation, formatting, and linked input files. Printed samples and inputs are reproduced as published.

A courier needs to deliver a package along a straight road, represented as a number line. The
package must be transported from position 𝑎 to position 𝑏, and the goal is to minimize the total
distance traveled by vehicle.
To assist with transportation, there is a teleporter installed between two fixed locations, 𝑥 and 𝑦.
If the package reaches 𝑥, it can be instantly teleported to 𝑦, and vice versa. However, the courier
still needs to travel by vehicle to and from any locations that are not connected by teleportation.
Determine the shortest total distance the courier must travel by vehicle to move the package
from 𝑎 to 𝑏.
INPUT FORMAT:
The first and only line of input contains four space-separated integers: a and b, describing the
start and end locations, followed by x and y, describing the teleporter. All positions are integers
in the range 0…100, and they are not necessarily distinct from each-other.
OUTPUT FORMAT:
A single integer, representing the minimum distance the courier must travel by vehicle to move
the package from 𝑎 to 𝑏.
SAMPLE INPUT:
3 10 8 2
SAMPLE OUTPUT:
3
In this example, the best strategy is to move the package from position 3 to position 2, teleport it
to position 8, then move it to position 10. The total distance requiring the vehicle is therefore 1 +
2 = 3.
Input
Case 1:
35 68 2 30
Case 2:
58 23 67 70

CHECK YOUR ANSWER

Try your answer.

Run your program in your own editor, then paste its output below. This checks the stated output; it does not assess your full program. Practice attempts do not affect competition scores.

Use the corresponding input from the question. For lists, brackets and commas are optional for numeric answers; text lists may also be entered one item per line.

Use the corresponding input from the question. For lists, brackets and commas are optional for numeric answers; text lists may also be entered one item per line.

Reveal worked answer

Case 1

33

Case 2

35

Compare the direct distance with both possible directions through the teleporter.

Reveal supplied answers

From the supplied Advanced answer key. Outputs are reproduced as provided.

Case 1

33

Case 2

35

Source: GIC 2025 Advanced Questions and the supplied Advanced answer key, March 2025 archive.