CF931A.Friends Meeting

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point _x_1 = a, another one is in the point _x_2 = b.

Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6.

The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.

两位朋友位于坐标轴 OxOx 上的整数坐标点处。其中一人位于点 x1=ax_1 = a,另一人位于点 x2=bx_2 = b。

每位朋友均可在直线上沿任意方向每次移动一个单位,且移动次数不限。当一位朋友移动时,其疲劳值按如下规则变化:第一次移动使其疲劳值增加 11,第二次移动增加 22,第三次增加 33,依此类推。例如,若一位朋友先向左移动、再向右移动(回到原点),然后再次向左移动,则其总疲劳值为 1+2+3=61 + 2 + 3 = 6。

这两位朋友希望在某个整数坐标点相遇。请确定他们相遇于同一点时所需的最小总疲劳值。

输入格式

The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend.

The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend.

It is guaranteed that a ≠ b.

第一行包含一个整数 aa(1 ≤ a ≤ 10001 ≤ a ≤ 1000)—— 第一位朋友的初始位置。

第二行包含一个整数 bb(1 ≤ b ≤ 10001 ≤ b ≤ 1000)—— 第二位朋友的初始位置。

保证 a ≠ ba ≠ b。

输出格式

Print the minimum possible total tiredness if the friends meet in the same point.

输出朋友们在同一点相遇时可能的最小总疲劳值。

输入输出样例

  • 输入#1

    3
    4

    输出#1

    1
  • 输入#2

    101
    99

    输出#2

    2
  • 输入#3

    5
    10

    输出#3

    9

说明/提示

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.

在第一个例子中,第一位朋友应向右移动一格(此时他们在位置 4 相遇),或者第二位朋友应向左移动一格(此时他们在位置 3 相遇)。这两种情况下,总疲劳值均为 11。

在第二个例子中,第一位朋友应向左移动一格,第二位朋友应向右移动一格。此时他们在位置 100100 相遇,总疲劳值为 1+1=21 + 1 = 2。

在第三个例子中,一种最优方案如下:第一位朋友向右移动三次,第二位朋友向左移动两次。此时他们在位置 88 相遇,总疲劳值为 1+2+3+1+2=91 + 2 + 3 + 1 + 2 = 9。

输入解题思路,AI测评打分。不知道怎么写?

首页