0% found this document useful (0 votes)
17 views2 pages

D. Add One To Some Elements of Subset: Problem Description

F-Talent Code Problem D

Uploaded by

hoangvanphong102
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

D. Add One To Some Elements of Subset: Problem Description

F-Talent Code Problem D

Uploaded by

hoangvanphong102
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

F-Talent Code 2024. 20/10/2024 D.

Add One to Some Elements of Subset

D. Add One to Some Elements of Subset


Constraint: Time Limit: 2 seconds, Memory: 256MB

Problem description
Samson received an array of integers 𝑎[0...𝑛] as a gift. His goal is to perform a number of
operations (potentially zero) such that all elements in the array become identical, meaning
𝑎0=𝑎1=⋯=𝑎𝑛. In each operation, he can select certain indices in the array and increase the
elements at those indices by 1. For instance, consider the array 𝑎=[4,2,1,6,2]. Samson could
choose the indices 0, 1, and 3, and increase the corresponding elements by 1. After this
operation, the array would look like 𝑎=[5,3,1,7,2]. What is the minimum number of operations
needed to make all elements in the array equal?

Input
The first line of the input contains a single integer 𝑡 (1 ≤ 𝑡 ≤ 10^4) — the number of test cases in the test.
The following are descriptions of the input test cases.
The first line of the description of each test case contains one integer 𝑛 (1≤𝑛≤50) — the array 𝑎.
The second line of the description of each test case contains 𝑛 integers 𝑎0,𝑎2,…,𝑎𝑛 (1 ≤ 𝑎𝑖 ≤
10^9) — elements of the array 𝑎.

Output
For each test case, println one integer which the minimum number of operations to make all elements
of the array 𝑎 equal.
Example 1
INPUT OUTPUT
3 3
6 4
342412 1
3
1000 1002 998
2
12 11
Explaination: the above testing data includes 3 test-cases
First test case:

• 𝑎=[3,4,2,4,1,2] take 𝑎2,𝑎4 and perform an operation plus one on them, as a result we
get 𝑎=[3,4,3,4,2,2].
• 𝑎=[3,4,3,4,2,2] we take 𝑎0,𝑎4,𝑎5 and perform an operation on them plus one, as a result we
get 𝑎=[4,4,3,4,3,3].

Page 1 of 2
F-Talent Code 2024. 20/10/2024 D. Add One to Some Elements of Subset

•𝑎=[4,4,3,4,3,3] we take 𝑎2,𝑎4,𝑎5 and perform an operation on them plus one, as a result we
get 𝑎=[4,4,4,4,4,4].
ð There are other sequences of 3 operations, after the application of which all elements become equal.

Second test case:


• 𝑎=[1000,1002,998] 2 times we take 𝑎0,𝑎2 and perform an operation plus one on them, as
a result we get 𝑎=[1002,1002,1000].
• 𝑎=[1002,1002,1000] also take 𝑎2 2 times and perform an operation plus one on it, as a
result we get 𝑎=[1002,1002,1002].

Third test case:


• 𝑎=[12,11] take 𝑎1 and perform an operation plus one on it, as a result we get 𝑎=[12,12].

Example 2
INPUT OUTPUT
1 0
31
1111111111111111111111111111111
Explaination: the above testing data includes only 1 test-cases,
This test-case has 31 elements
The third line is value of each element in array a

Page 2 of 2

You might also like