CF931A Friends Meeting
题目描述
在x-坐标轴(可以视为数轴)上有两个人,分别从$a$ 位置和$b$ 位置出发。
对于每个人,他可以往任意方向无限次地移动。当他第$i$ 次移动时,疲乏度增加$i$ 。例如,一个人第$1$ 次移动疲乏度增加$1$ ,第$2$ 次移动疲乏度增加$2$ (累计疲乏度为$3$ ),第$3$ 次移动增加$3$ (累计疲乏度为$6$ ),以此类推。
试求出这两个人在同一点相遇时疲乏度的和的最小值。
输入格式
分两行输入两个整数$a$ 和$b$ 。
$1 \le a,b \le 1000$ 且 $ a\neq b$ 。
输出格式
一个整数,即两人疲乏度的和的最小值。
### 样例解释
- 样例1:显然,其中一个人移动一个步即可,则答案为$1$ 。
- 样例2:显然,两人各移动一步,到达位置$100$ 。答案为$1+1=2$ 。
- 样例3:为到达位置$8$ ,左边的人向右移动$3$ 步,疲乏度为$1+2+3=6$ ;右边的人向左移动$2$ 步,疲乏度为$1+2=3$ 。答案为$6+3=9$ 。
感谢@hiuseues 提供的翻译
说明/提示
In the first example the first friend should move by one to the right (then the meeting happens at point $ 4 $ ), or the second friend should move by one to the left (then the meeting happens at point $ 3 $ ). In both cases, the total tiredness becomes $ 1 $ .
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point $ 100 $ , and the total tiredness becomes $ 1+1=2 $ .
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point $ 8 $ , and the total tiredness becomes $ 1+2+3+1+2=9 $ .