← March 2025 questions

MARCH 2025 / INTERMEDIATE / LEVEL 2 · QUESTION 2

Level 2 · Question 2

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 company wants to standardize a set of numerical values by adjusting them to a common
target in the most cost-efficient way. The cost of adjusting a value is the absolute difference
between the original and new value.
Given an array of N values, determine the minimum total adjustment cost required to make all
values equal.
The first line contains an integer N (1 ≤ N ≤ 100,000), the number of values.
The second line contains an array of N integers A₁, A₂, ..., A� (-1,000,000 ≤ Aᵢ ≤ 1,000,000),
representing the values.
Output a single integer representing the minimum total cost to make all values equal.
Sample Input:
5
50000 52000 54000 70000 75000
Sample Output:
43000
Explanation:
1.   Sort the values: 50000, 52000, 54000, 70000, 75000
2.   Choose the median value: 54000
3.   Compute the adjustment cost:
●    Adjust 50000 → 54000 (+4000)
●    Adjust 52000 → 54000 (+2000)
●    54000 stays the same (0)
●    Adjust 70000 → 54000 (-16000)
●    Adjust 75000 → 54000 (-21000)
4.   Total cost = 43000
Find the minimum total adjustment cost for the following input:
6
55000 60000 62000 75000 80000 50000

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.

Reveal worked answer

Your output

52000

Any target between 60000 and 62000 minimises the sum of absolute differences; the total is 52000.

Reveal supplied answer

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

Expected output

52000

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