CF1605A.A.M. Deviation
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A number a2 is said to be the arithmetic mean of two numbers a1 and a3 , if the following condition holds: a1+a3=2⋅a2 .
We define an arithmetic mean deviation of three numbers a1 , a2 and a3 as follows: d(a1,a2,a3)=∣a1+a3−2⋅a2∣ .
Arithmetic means a lot to Jeevan. He has three numbers a1 , a2 and a3 and he wants to minimize the arithmetic mean deviation d(a1,a2,a3) . To do so, he can perform the following operation any number of times (possibly zero):
- Choose i,j from {1,2,3} such that i=j and increment ai by 1 and decrement aj by 1
Help Jeevan find out the minimum value of d(a1,a2,a3) that can be obtained after applying the operation any number of times.
输入格式
The first line contains a single integer t (1≤t≤5000) — the number of test cases.
The first and only line of each test case contains three integers a1 , a2 and a3 (1≤a1,a2,a3≤108) .
输出格式
For each test case, output the minimum value of d(a1,a2,a3) that can be obtained after applying the operation any number of times.
输入输出样例
输入#1
3 3 4 5 2 2 6 1 6 5
输出#1
0 1 0
说明/提示
Note that after applying a few operations, the values of a1 , a2 and a3 may become negative.
In the first test case, 4 is already the Arithmetic Mean of 3 and 5 .
d(3,4,5)=∣3+5−2⋅4∣=0
In the second test case, we can apply the following operation:
(2,2,6) $\xrightarrow[\text{increment $ a_2 $}]{\text{decrement $ a_1 }} (1,3,6)
d(1,3,6)=∣1+6−2⋅3∣=1
It can be proven that answer can not be improved any further.
In the third test case, we can apply the following operations:
(1,6,5) $\xrightarrow[\text{increment $ a_3 $}]{\text{decrement $ a_2 }} (1,5,6) $\xrightarrow[\text{increment $ a_1 $}]{\text{decrement $ a_2 }} (2,4,6)
d(2,4,6)=∣2+6−2⋅4∣=0