P15624 [CodeChef] CEILSUM
提高-
题目描述

Read problem statements in [Russian] and [Mandarin Chinese].

You are given two integers A, B. You have to choose an integer X in the range [minimum(A, B), maximum(A, B)] such that:

$\Big \lceil \frac{B - X}{2} \Big \rceil + \Big \lceil \frac{X - A}{2} \Big \rceil$ is maximum.

What is the maximum sum you can obtain if you choose X optimally?

Note: $\lceil x \rceil$ : Returns the smallest integer that is greater than or equal to x (i.e rounds up to the nearest integer). For example$, \lceil 1.4 \rceil = 2, \lceil 5 \rceil = 5, \lceil -1.5 \rceil = -1, \lceil -3 \rceil = -3 , \lceil 0 \rceil = 0$.

------ Input Format ------

  • First line will contain T, number of testcases. Then the testcases follow.
  • Each testcase contains of a single line of input, two integers A, B.

------ Output Format ------

For each testcase, output the maximum sum of $\lceil \frac{B - X}{2} \rceil + \lceil \frac{X - A}{2} \rceil$.

------ Constraints ------

$1 ≤ T ≤ 10^{5}$
$1 ≤ A, B ≤ 10^{9}$

----- Sample Input 1 ------
3
2 2
1 11
13 6

----- Sample Output 1 ------
0
6
-3
----- explanation 1 ------
- In the first test case, there is only one possible value of $X$ which is equal to $2$. So the sum is equal to $\lceil \frac{2 - 2}{2} \rceil + \lceil \frac{2 - 2}{2} \rceil$ = $\lceil \ 0 \rceil + \lceil \ 0 \rceil$ = $0 + 0 = 0$.

  • In the second test case, we can choose $X$ to be $2$. So sum is equal to $\lceil \frac{11 - 2}{2} \rceil + \lceil \frac{2 - 1}{2} \rceil$ = $\lceil \ 4.5 \rceil + \lceil \ 0.5 \rceil$ = $5 + 1 = 6$. There is no possible way to choose an integer $X$ in the range $[1, 11]$ such that sum is greater than $6$.
输入格式

见题面

输出格式

见题面

样例输入
3 2 2 1 11 13 6
样例输出
0 6 -3